如何从XAML获取屏幕大小? [英] How to obtain screen size from xaml?
本文介绍了如何从XAML获取屏幕大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#上使用wpf设计GUI,我想从xaml代码获取屏幕大小(宽度和高度的值)。
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.
如何从C#代码中获取它们
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;
但我不知道如何从 XAML
代码。
But I don't know how to get them from XAML
code.
推荐答案
您可以阅读更多关于SystemParameters的这里
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>
这篇关于如何从XAML获取屏幕大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文