首页 > 解决方案 > 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>

标签: wpfvisual-studiouser-interface

解决方案


从根网格边距中删除 -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>

推荐阅读