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); } } ....... }
source share