wpf - WPF 网格未显示
问题描述
它应该是什么样子
它看起来像什么
所以我不确定为什么它没有显示顶部,有人可以帮忙吗?我无法解释更多。因为我不知道该怎么做,也不知道应该怎么解决。我在 WPF 上观看的视频非常糟糕,我无法理解。
<Window x:Class="EasyMath.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:EasyMath"
mc:Ignorable="d"
Title="Easy Math" Height="450" Width="580.96" Icon="Icon.png" ResizeMode="CanMinimize" Background="#FF2F3542" Foreground="Black" WindowStyle="None">
<Grid Margin="0,-45,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="151*"/>
<ColumnDefinition Width="430*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="41*"/>
<RowDefinition Height="409*"/>
</Grid.RowDefinitions>
<Grid Grid.ColumnSpan="2" Background="#FF2F3542" Margin="-1,0,0,10">
<Button x:Name="QuitApp" Content="Button" Margin="550,5,6,5" Background="#FFFF4757" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="QuitApplication"/>
<Button Content="Button" Margin="520,5,37,5" Background="#FFFFA502" BorderBrush="{x:Null}" Foreground="{x:Null}"/>
<Button Content="Button" Margin="489,5,67,5" Background="#FF2ED573" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="Button_Click"/>
</Grid>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Easy Math" VerticalAlignment="Top" Foreground="White" Height="35" Width="112" FontSize="24" Margin="10,-2,0,0"/>
</Grid>
解决方案
从根网格边距中删除 -45。有了这个,你说根网格应该缩进到顶部 45 像素有效地隐藏标题栏。
事实上,您可以完全从根网格中删除边距。
编辑:
看看你的草图,这可能是你正在寻找的东西。
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Easy Math"
WindowStartupLocation="CenterScreen"
ResizeMode="CanMinimize" AllowsTransparency="True"
Background="Transparent"
WindowStyle="None">
<Window.Resources>
<Style TargetType="Button" x:Key="titleBarButton">
<Setter Property="Width" Value="25"/>
<Setter Property="Height" Value="25"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="Foreground" Value="{x:Null}"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#FF2F3542">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Easy Math" VerticalAlignment="Top" Foreground="White" FontSize="24" Margin="10,0,0,0"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,10,0">
<Button Style="{StaticResource titleBarButton}" Background="#FF2ED573"/>
<Button Style="{StaticResource titleBarButton}" Background="#FFFFA502"/>
<Button Style="{StaticResource titleBarButton}" Background="#FFFF4757"/>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Height="10" Background="Transparent"/>
<Grid Grid.Row="2" Background="#FF2F3542">
</Grid>
</Grid>
</Window>
推荐阅读
- java - 每个项目的 Android Studio 3.6.3 构建都失败,没有任何错误
- c - 列表编译,但给出警告:不兼容的指针类型
- python - Python加入csv的最后两个元素
- django - 更新 m2m 字段中的对象时如何使用 django 信号更新模型字段?
- microsoft-graph-api - Azure AD B2C 在生产 5-6 个月后于周一停止工作
- sql - DB2 中的 datastage 转换函数的等价物是什么
- mysql - 在对另一列求和时选择具有最小日期的行
- python - 如何在 python 中的这些类之间创建这样的关联?
- javascript - 在 R Leaflet 中以特定缩放级别显示图层
- javascript - 如何使用正则表达式从 javascript 中的 HTML 标记中过滤字符串