Is there a SharedSizeGroup equivalent for ListViews inside ItemsControl?

I use ItemsControl representing countries. For each country, I use ListView to display my cities:

<ItemsControl ItemsSource="{Binding Countries}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ListView Margin="10" ItemsSource="{Binding Cities}"> <ListView.View> <GridView> <GridViewColumn Width="140" Header="City" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Width="90" Header="Population" DisplayMemberBinding="{Binding Population}" /> </GridView> </ListView.View> </ListView> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 

Result:

enter image description here

I need that whenever the user changes the width of the column in the first list, the second adjusts its width (something like SharedGroupSize for grids).

How can i do this?

+4
source share
1 answer

Create a custom UserControl that has a dependency property for each column width. Then the bilateral width of the column binding to them.

 <UserControl x:Class="CountryList" x:Name="countryList"> <ItemsControl ...... <GridView> <GridViewColumn Width="{Binding ColumnWidth1,Mode=TwoWay, ElementName=countryList}" Header="City" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Width="{Binding ColumnWidth2,Mode=TwoWay, ElementName=countryList}" Header="Population" DisplayMemberBinding="{Binding Population}" /> </GridView> ....... </UserControl> 

and code for

 public partial class CountryList : UserControl { public static readonly DependencyProperty ColumnWidth1Property = DependencyProperty.Register("ColumnWidth1", typeof(int), typeof(CountryList), new PropertyMetadata(140)); public int ColumnWidth1 { get { return (int)GetValue(ColumnWidth1Property); } set { SetValue(ColumnWidth1Property, value); } } ....... } 
0
source

All Articles