I want to change the number of columns in a ListView to the screen metrics, i'm using the following code for this.
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
this.SizeChanged += OnWindowSizeChanged;
}
protected void OnWindowSizeChanged(object sender, SizeChangedEventArgs e)
{
double newWindowHeight = e.NewSize.Height;
double newWindowWidth = e.NewSize.Width;
double prevWindowHeight = e.PreviousSize.Height;
double prevWindowWidth = e.PreviousSize.Width;
LabelXY.Content = newWindowHeight.ToString() + newWindowWidth.ToString();
}
And set column with xaml;
<UniformGrid Columns="5"/>
Everything's fine, there are 5 columns.
But if the window width is less than 1200 px, I want 4 columns.
Came to my mind first to make it binding, like this then i failed.
<UniformGrid Columns="{Binding Path=ColumnNum}"/>
So if it is not binding, possible to programmatically change the number of columns with C#? Thanks...