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
Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
But I don't know how to get them from XAML
code.
Use window. innerWidth and window. innerHeight to get the current screen size of a page.
In a Xamarin. Forms application, XAML is mostly used to define the visual contents of a page and works together with a C# code-behind file. The code-behind file provides code support for the markup. Together, these two files contribute to a new class definition that includes child views and property initialization.
Extensible Application Markup Language (XAML) is a declarative language that's based on XML. XAML is used extensively in the following types of applications to build user interfaces: Windows Presentation Foundation (WPF) apps. Universal Windows Platform (UWP) apps.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With