WPF中的菜单项正在被截止

时间:2013-06-23 00:09:12

标签: c# wpf menu

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

2 个答案:

答案 0 :(得分:4)

我认为你遇到的问题与你对某些对象强制执行的边距和高度有关,这也会使重新调整窗口大小变得非常棘手,而结果看起来并不奇怪。 / p>

此外,您的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

祝你好运!

答案 1 :(得分:1)

这很好用(不要忘记添加你的Click事件;-)):

    <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>