gpt4 book ai didi

c# - WPF 中的菜单项被切断

转载 作者:行者123 更新时间:2023-12-02 21:58:59 26 4
gpt4 key购买 nike

我正在开发一个 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

祝你好运!

关于c# - WPF 中的菜单项被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17256547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com