I\'m using wpf on C# to design GUI, and I want to get screen size (The value of Width and Height) from xaml code.
I knew how to get them from C# code as
This will work. You can read more here about SystemParameters
<Window x:Class="WpfApplication1.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">
<StackPanel>
<TextBlock Text="{Binding Source={x:Static SystemParameters.FullPrimaryScreenHeight}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}" />
</StackPanel>
</Window>
Check out the SystemParameters class: http://msdn.microsoft.com/de-de/library/system.windows.systemparameters.fullprimaryscreenheight.aspx
You can use it like this:
<Object Attribute="{x:Static SystemParameters.FullPrimaryScreenHeight}"/>
(You could also use the x:Static notation to query the Windows Forms properties, however if you're developing a WPF application the SystemParameters class might be the way to go)
Say your parent container in the XAML is grid, name it as grdForm
In the code behind can get the dimensions as
double width=grdForm.ActualWidth
double height=grdForm.ActualHeight