WPF中的菜单项被切断
本文关键字:菜单项 WPF | 更新日期: 2023-09-27 18:19:43
我正在开发一个WPF,由于某种原因,我的菜单栏底部一直被截断。
我搜索了一下,发现了一些答案,说这是.NET v3.5框架中的一个错误,在v4.0中已经修复。但是,我当前的项目设置是为.NET v4.5设置的。
我的WPF预览看起来很完美。当我去运行程序时,它就被切断了。由于我的低代表性,我无法显示图像,因此以下是链接:
http://i40.tinypic.com/o0tsvn.jpg
http://i43.tinypic.com/sgmhk7.jpg
如有任何帮助,我们将不胜感激。
<Window x:Name="mainWindow" x:Class="Kewpon.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Kewpon" Height="585.455" Width="704.454">
<Grid>
<ListView x:Name="itemListView" HorizontalAlignment="Left" Height="514" Margin="0,21,0,0" VerticalAlignment="Top" Width="227">
<ListView.View>
<GridView>
<GridViewColumn Width ="155" Header="Item Name" DisplayMemberBinding="{Binding itemName}"/>
<GridViewColumn Width ="60" Header="Cost" DisplayMemberBinding="{Binding retailCost}"/>
</GridView>
</ListView.View>
</ListView>
<Label x:Name="totalLabel" Content="Total:" HorizontalAlignment="Left" Margin="232,119,0,0" VerticalAlignment="Top"/>
<Label x:Name="totalNoTaxLabel" Content="Total before tax:" HorizontalAlignment="Left" Margin="232,26,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.417,1.741"/>
<Label x:Name="totalNoTaxLabel_Copy" Content="Tax: " HorizontalAlignment="Left" Margin="232,88,0,0" VerticalAlignment="Top"/>
<Label x:Name="totalNoCouponLabel" Content="Total before coupons:" HorizontalAlignment="Left" Margin="232,57,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.417,1.741"/>
<Menu x:Name="mainMenu" DockPanel.Dock="Top" Margin="0,-2,0,534">
<MenuItem Header="_File">
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
<Separator/>
<MenuItem Header="Close" Click="closeMenuItem_Click"/>
</MenuItem>
<MenuItem Header="Add">
<MenuItem Header="Add Item" Click="addItemMenuItem_Click"/>
<MenuItem Header="Add Coupon" Click="addCouponMenuItem_Click"/>
</MenuItem>
<MenuItem Header="Remove" Click="removeMenuItem_Click"/>
</Menu>
</Grid>
</Window>
我认为您遇到的问题与您在某些对象上强制执行的边距和高度有关,这也会使重新调整窗口大小变得非常棘手,而不会使结果看起来有点奇怪。
此外,您的MenuItem
设置了DockPanel.Dock
,并且似乎没有相应的DockPanel。
我已经构建了一个带有Dockpanel的快速变体,尽管只使用网格也可以轻松地进行布局。
<Window x:Name="mainWindow" x:Class="Kewpon.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Kewpon" Height="585.455" Width="704.454">
<Grid>
<DockPanel LastChildFill="True">
<Menu x:Name="mainMenu" DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
<Separator/>
<MenuItem Header="Close"/>
</MenuItem>
<MenuItem Header="Add">
<MenuItem Header="Add Item" />
<MenuItem Header="Add Coupon" />
</MenuItem>
<MenuItem Header="Remove" />
</Menu>
<ListView x:Name="itemListView" HorizontalAlignment="Left" Width="227" DockPanel.Dock="Left">
<ListView.View>
<GridView>
<GridViewColumn Width ="155" Header="Item Name" DisplayMemberBinding="{Binding itemName}"/>
<GridViewColumn Width ="60" Header="Cost" DisplayMemberBinding="{Binding retailCost}"/>
</GridView>
</ListView.View>
</ListView>
<UniformGrid Rows="4" DockPanel.Dock="Left" Height="200" VerticalAlignment="Top">
<Label x:Name="totalLabel" Content="Total:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label x:Name="totalNoTaxLabel" Content="Total before tax:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label x:Name="totalNoTaxLabel_Copy" Content="Tax: " HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label x:Name="totalNoCouponLabel" Content="Total before coupons:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</UniformGrid>
</DockPanel>
</Grid>
</Window>
这也值得快速查看,以获取更多信息。
http://msdn.microsoft.com/en-us/library/ms745058.aspx
祝你好运!
这很好用(不要忘记添加您的点击事件;-):
<Window x:Name="mainWindow" x:Class="Kewpon.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Kewpon" Height="585.455" Width="704.454">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Menu x:Name="mainMenu" Height="20" Grid.Row="0" >
<MenuItem Header="_File">
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
<Separator/>
<MenuItem Header="Close"/>
</MenuItem>
<MenuItem Header="Add">
<MenuItem Header="Add Item" />
<MenuItem Header="Add Coupon"/>
</MenuItem>
<MenuItem Header="Remove" />
</Menu>
<Grid Grid.Row="1">
<ListView x:Name="itemListView" HorizontalAlignment="Left" Height="514" Margin="0,5,0,0" VerticalAlignment="Top" Width="227">
<ListView.View>
<GridView>
<GridViewColumn Width ="155" Header="Item Name" DisplayMemberBinding="{Binding itemName}"/>
<GridViewColumn Width ="60" Header="Cost" DisplayMemberBinding="{Binding retailCost}"/>
</GridView>
</ListView.View>
</ListView>
<Label x:Name="totalLabel" Content="Total:" HorizontalAlignment="Left" Margin="232,119,0,0" VerticalAlignment="Top"/>
<Label x:Name="totalNoTaxLabel" Content="Total before tax:" HorizontalAlignment="Left" Margin="232,26,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.417,1.741"/>
<Label x:Name="totalNoTaxLabel_Copy" Content="Tax: " HorizontalAlignment="Left" Margin="232,88,0,0" VerticalAlignment="Top"/>
<Label x:Name="totalNoCouponLabel" Content="Total before coupons:" HorizontalAlignment="Left" Margin="232,57,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.417,1.741"/>
</Grid>
</Grid>
</Window>