简体   繁体   中英

Menu item in WPF is being cutoff

I am developing a WPF and for some reason the bottom of my menu bar keeps getting cutoff.

I searched and found a few answers stating that it is a bug in the .NET v3.5 framework and that it was fixed in v4.0. However, my current project settings are set for .NET v4.5.

The preview of my WPF looks perfect. When I go to run the program then that is when it gets cutoff. I cannot show images due to my low rep so here are the links:

http://i40.tinypic.com/o0tsvn.jpg

http://i43.tinypic.com/sgmhk7.jpg

Any help would be greatly appreciated.

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

I think the problem you're having is related to the margins and height you're enforcing on some of your objects, which will also make it quite tricky to re-size your window without the results looking a bit strange.

Also, your MenuItem has DockPanel.Dock set, and there doesn't seem to be a corresponding DockPanel.

I've knocked up a quick variant with a Dockpanel in place, although you could make the layout just as easily using only grids.

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

This is also worth a quick look, for additional info.

http://msdn.microsoft.com/en-us/library/ms745058.aspx

Good luck!

This works fine ( do not forget to add your Click events ;-) ):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM