Set maximum available width for Stackpanel
-
I don't do xaml that often, so some (probably) basic stuff bites me in the ass now and then. The small problem I have now is that I can't seem to get a stackpanel take the correct size. This is basicly how the form looks like:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> ..... Here a bunch of controls are added and then come the stackpanels <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal"> And again some controls in the stackpanel </StackPanel> .....
What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice. I would like that the stackpanel uses the full column-width of the grid. I tried binding the width of the stackpanel to the column, widht like this:
First name the column where the stackpanel is in <Grid.ColumnDefinitions> .... <ColumnDefinition **x:Name="BindColumn"** Width="Auto"/> .... </Grid.ColumnDefinitions> Then bind to the width like: <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" **Width="{Binding ElementName=BindColumn, Path=Width}"**\>
This doesn't work. It doesn't seem like I want something that should be difficult to make it work, so I'm probably offtrack here with my way of thinking. Thanks to anyone if they can put me on the right track again. Greets, Davy
-
I don't do xaml that often, so some (probably) basic stuff bites me in the ass now and then. The small problem I have now is that I can't seem to get a stackpanel take the correct size. This is basicly how the form looks like:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> ..... Here a bunch of controls are added and then come the stackpanels <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal"> And again some controls in the stackpanel </StackPanel> .....
What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice. I would like that the stackpanel uses the full column-width of the grid. I tried binding the width of the stackpanel to the column, widht like this:
First name the column where the stackpanel is in <Grid.ColumnDefinitions> .... <ColumnDefinition **x:Name="BindColumn"** Width="Auto"/> .... </Grid.ColumnDefinitions> Then bind to the width like: <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" **Width="{Binding ElementName=BindColumn, Path=Width}"**\>
This doesn't work. It doesn't seem like I want something that should be difficult to make it work, so I'm probably offtrack here with my way of thinking. Thanks to anyone if they can put me on the right track again. Greets, Davy
GDavy wrote:
What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice.
does not look as nice as...... what? A StackPanel will always take up only the space it needs for the controls in the stacking direction (in this case, width). Once you decide how the extra space should be used (given to the last control, left blank, shared among all controls, ...), you can determine which other container to use instead.
-
I don't do xaml that often, so some (probably) basic stuff bites me in the ass now and then. The small problem I have now is that I can't seem to get a stackpanel take the correct size. This is basicly how the form looks like:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> ..... Here a bunch of controls are added and then come the stackpanels <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal"> And again some controls in the stackpanel </StackPanel> .....
What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice. I would like that the stackpanel uses the full column-width of the grid. I tried binding the width of the stackpanel to the column, widht like this:
First name the column where the stackpanel is in <Grid.ColumnDefinitions> .... <ColumnDefinition **x:Name="BindColumn"** Width="Auto"/> .... </Grid.ColumnDefinitions> Then bind to the width like: <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" **Width="{Binding ElementName=BindColumn, Path=Width}"**\>
This doesn't work. It doesn't seem like I want something that should be difficult to make it work, so I'm probably offtrack here with my way of thinking. Thanks to anyone if they can put me on the right track again. Greets, Davy