WPF separator between grid buttons

I have a grid with 4 buttons ... 1 row, 4 columns. I am looking for a way to visually group two buttons to the left of two to the right. I was looking for a way to do this with a separator, but it doesn't seem to play with the Grid, preferring the StackPanel.

Is this the right control?
If so, how do you make the unit in columns (in this case, filled with buttons)?

Thanks.

+6
wpf separator
source share
4 answers

I usually use a simple selection to add a fixed width column between the buttons. In fact, you can use a different background color or insert an image

+1
source share

In case someone else stumbles upon this, the simplest solution:

<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" /> 
+20
source share

Have you tried GridSplitter ?

 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Height="*" /> <ColumnDefinition Height="Auto" /> <ColumnDefinition Height="100" /> <ColumnDefinition Height="100" /> </Grid.ColumnDefinitions> <Button/> <Button/> <GridSplitter ResizeDirection="Columns" Grid.Column="2" Height="Auto" Width="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/> <Button/> </Grid> 
+6
source share

You can use Separator if you configured it correctly. By default, a horizontal line is created. You have to apply different styles to make it vertical. See this post on how to style it as a vertical line in a WPF grid:

Discussion CodeProject

The discussion also mentions that the StatusBar applies some styles to Separator elements if you do not complete them in the StatusBarItems. Maybe StackPanel is doing something similar.

+1
source share

All Articles