C# WPF 界面根据分辨率的大小自适应

来源:互联网 发布:淘宝判断虚假交易 编辑:程序博客网 时间:2024/05/02 04:23

一般程序做界面的时候都要考虑多分辨率适配的问题,这个问题说难不难,但是在MFC的架构下可以烦死人,最近改用C#的WPF架构来做一般的应用程序也碰到了这个问题,没想到解决的手法却出奇的简单,只是在代码中插入两句话就行了。不多说了,代码如下:

<Window x:Class="ResolutionRatioAdaptDemo.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"        xmlns:local="clr-namespace:ResolutionRatioAdaptDemo"        mc:Ignorable="d"        Title="MainWindow" Height="350" Width="1878.633">    <Viewbox><!--插入语句,实现屏幕自适应-->        <Grid>            <Button x:Name="test" Content="分辨率测试" Margin="1468,178,88,37"/>        </Grid>    </Viewbox></Window>
1 1
原创粉丝点击