C# 跨不同屏幕大小缩放WPF应用程序中的元素

C# 跨不同屏幕大小缩放WPF应用程序中的元素,c#,wpf,C#,Wpf,我正在尝试创建一个全屏WPF应用程序,它可以跨多个屏幕大小进行缩放。然而,我发现当程序在不同的屏幕大小中运行时,窗口元素不能正确地缩放和定位 i、 e.2013年 i、 e.何时运行 我如何使程序相应地扩展?例如,我希望将按钮定位在屏幕的左侧或右侧,并放大列表框以填充屏幕 这是我目前的代码: <Window x:Class="FYP.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/prese

我正在尝试创建一个全屏WPF应用程序,它可以跨多个屏幕大小进行缩放。然而,我发现当程序在不同的屏幕大小中运行时,窗口元素不能正确地缩放和定位

i、 e.2013年

i、 e.何时运行

我如何使程序相应地扩展?例如,我希望将按钮定位在屏幕的左侧或右侧,并放大列表框以填充屏幕

这是我目前的代码:

<Window x:Class="FYP.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="2*"/>
        </Grid.ColumnDefinitions>
        <Button Content="View Messages" Grid.Column="1" HorizontalAlignment="Left" Margin="203,20,0,0" VerticalAlignment="Top" Width="97" Name="ViewMessagesButton"/>
        <Button Content="Log Out" Grid.Column="1" HorizontalAlignment="Left" Margin="305,20,0,0" VerticalAlignment="Top" Width="65" Name="LogOutButton"/>
        <TextBlock HorizontalAlignment="Left" Margin="20,20,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="20" Name="DateTimeTextBlock"/>
        <ListBox HorizontalAlignment="Left" Height="434" Margin="20,60,0,0" VerticalAlignment="Top" Width="350"/>
        <ListBox HorizontalAlignment="Left" Height="135" Margin="20,60,0,0" VerticalAlignment="Top" Width="350" Grid.Column="1"/>
        <ListBox HorizontalAlignment="Left" Height="278" Margin="20,216,0,0" VerticalAlignment="Top" Width="350" Grid.Column="1"/>
    </Grid>
</Window>


您的问题是您已经为所有控件设置了具体的大小。删除控件上的宽度和高度,并按需要设置边距。

删除宽度和高度,并将水平和垂直对齐设置为拉伸。

如果确实希望对象向上或向下缩放(而不是调整大小),如果希望排列的纵横比保持最初的排列方式,则应使用控件