为什么这些WPF元素没有完全显示?

时间:2015-09-02 09:38:51

标签: c# wpf visual-studio-2015

我在C#中编写了一个程序,它使用了使用WPF开发的用户界面和XAML中的标记。 但是,当我启动应用程序窗口时,enter image description here

这种情况发生了。

但是,当我最大化窗口时,enter image description here

这种情况发生了。

似乎我的按钮要么没有正确地在显示画布上绘制(?),要么它们没有被正确渲染(?)。

如何修复此问题? (按钮必须按照后一图像中显示的方式显示 - 即使窗口是平铺的。)

(该程序是使用Visual Studio 2015使用DotNet 4.5.2构建的)

更新:我忘了为窗口添加XAML代码 - 所以就是这样。

<Window x:Class="NKryptorTester_WPF.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:NKryptorTester_WPF"
    mc:Ignorable="d"
    Title="NKryptor Desktop" Height="600" Width="1024">
<Grid>
    <Button x:Name="ButtonSignup" Click="ActionSignup" FontWeight="Light" Foreground="White" Content="Signup" BorderThickness="0" Height="50" Width="250" FontSize="20" Margin="385,240,381,279" Background="#FF21877E"/>
    <Button x:Name="ButtonSignin" Click="ActionSignin" FontWeight="Light" Foreground="White" Content="Signin" BorderThickness="0" Height="50" Width="250" FontSize="20" Margin="385,290,381,229" Background="#FF712687"/>
</Grid>

1 个答案:

答案 0 :(得分:0)

你必须摆脱固定保证金并尝试类似的东西:

      <Grid>
        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
          <Button x:Name="ButtonSignup" Click="ActionSignup" FontWeight="Light" Foreground="White" Content="Signup" BorderThickness="0" Height="50" Width="250" FontSize="20" Background="#FF21877E"/>
          <Button x:Name="ButtonSignin" Click="ActionSignin" FontWeight="Light" Foreground="White" Content="Signin" BorderThickness="0" Height="50" Width="250" FontSize="20" Background="#FF712687"/>
        </StackPanel>
      </Grid>