In my application I have a ListView
where I defined its ItemTemplate
as follows:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Background="Aqua">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="ParameterIconSize" />
<ColumnDefinition Width="Auto" SharedSizeGroup="ParameterDescriptionSize" />
<ColumnDefinition Width="Auto" SharedSizeGroup="ParameterValueSize" />
</Grid.ColumnDefinitions>
<Image
Grid.Column="0"
MaxHeight="50"
Margin="5"
Grid.IsSharedSizeScope="True"
Source="{Binding Path=Icon}" />
<TextBlock
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Grid.IsSharedSizeScope="True"
Text="{Binding Path=Parameter.NameKey}" />
<TextBox
Grid.Column="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
Grid.IsSharedSizeScope="True"
Text="{Binding Path=Parameter.Value}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Such code produces this output:
As you can see, nearly every column has a different width, whilst I wanted to make them even. I thought that going with SharedSizeGroup
was the right way, but clearly there is something I am missing...
(PS: I had to set the maxHeight in the Image element because if not this would show:
)
I would like to have all three columns the same size, determined by these criteria:
EDIT 2: I forgot to specify that I want the textboxes in column 2 to be the same size, filling the available space.
You have to enable the SharedSize
functionality in the parent element.
<ListView Grid.IsSharedSizeScope="True">
<ListView.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.