为什么我看不到我创建的菜单
本文关键字:菜单 创建 我看 看不到 为什么 | 更新日期: 2023-09-27 18:33:17
所以我正在创建一个小型的wpf应用程序,我希望它有一个菜单。我创建了菜单,但没有,但是当我运行程序时,菜单根本不显示。菜单的代码当前为:
<Window x:Class="TBA_Alpha.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TBA LogIn" Height="350" Width="525">
<Grid>
<PasswordBox x:Name="tbPsw" HorizontalAlignment="Left" Margin="214,143,0,0" VerticalAlignment="Top" Width="133" SelectionBrush="Black" Background="White">
<PasswordBox.BorderBrush>
<LinearGradientBrush EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
<GradientStop Color="#FFABADB3" Offset="0.05"/>
<GradientStop Color="#FFE2E3EA" Offset="0.07"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</PasswordBox.BorderBrush>
</PasswordBox>
<TextBox x:Name="tbUId" HorizontalAlignment="Left" Height="23" Margin="214,94,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="133" SelectionBrush="Black">
<TextBox.Background>
<SolidColorBrush Color="White"/>
</TextBox.Background>
<TextBox.BorderBrush>
<LinearGradientBrush EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
<GradientStop Color="#FFABADB3" Offset="0.05"/>
<GradientStop Color="#FFE2E3EA" Offset="0.07"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</TextBox.BorderBrush>
</TextBox>
<Button Content="LogIn" HorizontalAlignment="Left" Margin="239,200,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<TextBlock HorizontalAlignment="Left" Margin="214,73,0,0" TextWrapping="Wrap" Text="Your UserID:" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="214,122,0,0" TextWrapping="Wrap" Text="Your Password:" VerticalAlignment="Top"/>
<Menu HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="43" BorderThickness="1">
<MenuItem Header=" New " RenderTransformOrigin="0.5,0.5" Width="63" Height="36" Background="White" Visibility="Visible" AllowDrop="True" IsHitTestVisible="True">
<MenuItem Header=" User " Click="newUser"/>
</MenuItem>
</Menu>
</Grid>
任何帮助都将不胜感激,谢谢。
编辑:为 wpf 添加了整个 XAML 代码,其中菜单接近代码末尾
编辑:删除所有附加内容并仅保留标题后,仍然遇到相同的问题
编辑:在不同的干净项目中尝试了代码,它起作用了,谢谢
问题是大多数控件使用 Magrin
属性来分隔自身,而不是Grid
的功能。由于它们都没有指定附加的属性Grid.Row
,因此它们都在同一行中。由于Menu
没有指定Margin
,因此它位于Grid
的顶部,因此与其他控件重叠。
尝试使用实际网格行
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<PasswordBox x:Name="tbPsw" HorizontalAlignment="Left" Grid.Row="0" VerticalAlignment="Top" Width="133" SelectionBrush="Black" Background="White">
<PasswordBox.BorderBrush>
<LinearGradientBrush EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
<GradientStop Color="#FFABADB3" Offset="0.05"/>
<GradientStop Color="#FFE2E3EA" Offset="0.07"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</PasswordBox.BorderBrush>
</PasswordBox>
<TextBox x:Name="tbUId" HorizontalAlignment="Left" Height="23" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="133" SelectionBrush="Black">
<TextBox.Background>
<SolidColorBrush Color="White"/>
</TextBox.Background>
<TextBox.BorderBrush>
<LinearGradientBrush EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
<GradientStop Color="#FFABADB3" Offset="0.05"/>
<GradientStop Color="#FFE2E3EA" Offset="0.07"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</TextBox.BorderBrush>
</TextBox>
<Button Content="LogIn" HorizontalAlignment="Left" Grid.Row="2" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<TextBlock HorizontalAlignment="Left" Grid.Row="3" TextWrapping="Wrap" Text="Your UserID:" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Grid.Row="4" TextWrapping="Wrap" Text="Your Password:" VerticalAlignment="Top"/>
<Menu Grid.Row="5" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="43" BorderThickness="1">
<MenuItem Header=" New " RenderTransformOrigin="0.5,0.5" Width="63" Height="36" Background="White" Visibility="Visible" AllowDrop="True" IsHitTestVisible="True">
<MenuItem Header=" User " Click="newUser"/>
</MenuItem>
</Menu>
</Grid>