Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximizing WPF Doesn't Update Width?

The Width property of the screen doesn't seem to update to the fully maximized width when maximizing a window. If I resize it everything works fine, but not when maximizing.

The code I have is as follows:

private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
    UpdateColumns();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    UpdateColumns();
}

private void UpdateColumns()
{
    ColumnCount = Math.Round(Width/150);
    statusBarItemColumnCount.Content = ColumnCount;
    button1.Content = ColumnCount + " " + Width;
}

private void Window_StateChanged(object sender, EventArgs e)
{
    UpdateColumns();
}
like image 753
Adron Avatar asked Mar 13 '09 03:03

Adron


2 Answers

Take a look at ActualWidth, rather than Width.

like image 199
Dominic Hopton Avatar answered Sep 19 '22 02:09

Dominic Hopton


try using ActualWidth instead of Width, that should fix it

like image 43
MrTelly Avatar answered Sep 21 '22 02:09

MrTelly