Apparently when using a SharedSizeGroup, you can't use star sizing (*). This has been discussed here: Grid's SharedSizeGroup and * sizing
Unfortunately, in that discussion they don't really offer a viable solution to the problem.
I would like to display a list of controls, one control per row, with the following layout:
(Name)(Entry textbox)(X Button)
It should look like this:
Description [ ] X
Name [ ] X
ID [ ] X
But instead I'm getting
Description [] X
Name [] X
ID [] X
Column 1 should be as wide as the longest word. Column 2, the entry textbox, should stretch to fill all the remaining space (*), but that doesn't work with SharedSizeGroup as previously discussed. The * is being treated as Auto, hence the non-stretching.
Any ideas? Here's the XAML:
<ItemsControl ItemsSource="{Binding FilterList}" Margin="5,0,5,0" Grid.IsSharedSizeScope="True">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="5,0,5,0" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Column0" Width="Auto"/>
<ColumnDefinition SharedSizeGroup="Column1" Width="*"/>
<ColumnDefinition SharedSizeGroup="Column2" Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding FilterLabel}" HorizontalAlignment="Right"/>
<TextBox Grid.Column="1" Height="20" Text="{Binding FilterString, UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="2" Content=" X " Margin="2" Visibility="{Binding ClearFilterVis}" Command="{Binding ClearFilterCommand}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
That's because you set
Grid's HorizontalAlignment
to Left instead of Stretch. Or just removeGrid's HorizontalAlignment
setting. And as @Highcore said, you don't seems to needSharedSizeGroup
in this case.