views:

436

answers:

2

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();
    }
+5  A: 

Take a look at ActualWidth, rather than "Width".

dhopton
Thank you! This also works for ActualHeight.
Richard Morgan
+1  A: 

try using ActualWidth instead of Width, that should fix it

MrTelly