【问题标题】:Layout issue with visual c#Visual c#的布局问题
【发布时间】:2017-05-27 20:20:15
【问题描述】:

我正在 Visual Studio 2017 (Visual C#) 上创建一个简单的 WPF 应用程序。 我有这个表格:

<Window x:Class="HelloWPFApp.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:HelloWPFApp"
        mc:Ignorable="d"
        Title="Greetings" Height="350" Width="525">
    <Grid Height="319" VerticalAlignment="Bottom">
        <Grid.RowDefinitions>
            <RowDefinition Height="192*"/>
            <RowDefinition Height="41*"/>
            <RowDefinition Height="86*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Center" Height="16" Width="329" Margin="102,131,86,45"/>
        <RadioButton x:Name="rbHello" Content="Hello" HorizontalAlignment="Left" Margin="102,2,0,0" VerticalAlignment="Top" Height="15" Width="47" Grid.Row="1"/>
        <RadioButton x:Name="rbGoodbye" Content="Goodbye" HorizontalAlignment="Left" Margin="337,2,0,0" VerticalAlignment="Top" Height="15" Width="67" Grid.Row="1"/>
        <Button Content="Display" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="231,2,0,0" Click="Button_Click" Height="20" Grid.Row="2"/>
    </Grid>
</Window>

这是预览:

当我编译时,这是一个窗口中的结果

如果我尝试使用全屏,它会向我显示:

为什么要这样做?我该如何解决? (这是Microsoft Documentation的一个例子!)

【问题讨论】:

  • 这看起来像 WPF,而不是 WinForms。您提供的链接是 WPF 示例。
  • 对不起,WPF 是正确的,我有点糊涂

标签: c# visual-studio xaml grid visual-studio-2017


【解决方案1】:

这是 WPF 而不是 Windows 窗体。而且你的定位全错了。当您拖放东西时,它使用绝对定位。如果你想在中心使用
&lt;Grid VerticalAlignment="Center" HorizontalAlignment="Center"&gt;
但是here是开始学习系统的好地方

【讨论】:

  • 谢谢,很有用
猜你喜欢
  • 1970-01-01
  • 2013-11-23
  • 2018-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多