Get Size of Window when is Maximized in WPF

user1040567 picture user1040567 · Dec 7, 2011 · Viewed 7.7k times · Source

i search for a way to get the Width-Property of an Maximized WPF Window.

Any Ideas how can i get the absolute value?

Thanks a lot.

Answer

Markus picture Markus · Dec 7, 2011

What about this:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Label Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}, Path=ActualWidth}"></Label>
    </Grid>
</Window>

Just use the ActualWidth property.