Wpf菜单栏问题 - menuitem没有出现在rundtime [英] Wpf menubar problem - menuitem are not showing up at rundtime

查看:81
本文介绍了Wpf菜单栏问题 - menuitem没有出现在rundtime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,

我正在使用以下代码,并且不知道为什么在运行时菜单项没有出现。

感谢您的支持:)



我尝试过:



Hey folks,
I'm using following code and have no idea why at runtime the menuitems are not showing up.
Appreciate your support:)

What I have tried:

<pre><Window

    x:Class="FFApp.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:local="clr-namespace:FFApp"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    Title="FFApp"

    Width="1360"

    Height="768"

    MinWidth="{Binding WindowMinimumWidth}"

    MinHeight="{Binding WindowMinimumHeight}"

    AllowsTransparency="true"

    FontFamily="Yu Gothic"

    WindowStartupLocation="CenterScreen"

    WindowStyle="None"

    mc:Ignorable="d">

    <Window.Resources>
        <Style TargetType="{x:Type local:MainWindow}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <!--  Outer border with the dropshadow margin  -->
                        <Border Padding="{Binding OuterMarginSizeThickness, FallbackValue=10}">
                            <Grid>
                                <!--  Opacity mask for corners on grid  -->
                                <Border
                                    x:Name="Container"
                                    Background="{StaticResource BackgroundLight}"
                                    CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}" />
                                <!--  Window border and dropshadown  -->
                                <Border Background="{StaticResource BackgroundGold}" CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}">
                                    <Border.Effect>
                                        <DropShadowEffect Opacity="0.8" ShadowDepth="0" />
                                    </Border.Effect>
                                </Border>
                                <!--  The main window content  -->
                                <Grid>
                                    <!--  Corner clipping  -->
                                    <Grid.OpacityMask>
                                        <VisualBrush Visual="{Binding ElementName=Container}" />
                                    </Grid.OpacityMask>

                                    <Grid.RowDefinitions>
                                        <!--  Header  -->
                                        <RowDefinition Height="{Binding TitleHeightGridLength, FallbackValue=32}" />
                                        <!--  Input Area  -->
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>

                                    <!--  TitleBar  -->
                                        <!--  Header  -->
                                        <Menu >
                                            <MenuItem Header="_File">
                                                <MenuItem Header="_New..." />
                                                <Separator />
                                                <MenuItem Header="_Open..." />
                                                <Separator />
                                                <MenuItem Header="_Save" />
                                                <MenuItem Header="_Save As..." />
                                                <Separator />
                                                <MenuItem Header="_Exit" />
                                            </MenuItem>
                                            <MenuItem Header="_Edit">
                                                <MenuItem Command="Cut" Header="_Cut" />
                                                <MenuItem Command="Copy" Header="_Copy" />
                                                <MenuItem Command="Paste" Header="_Paste" />
                                            </MenuItem>
                                            <MenuItem Header="_View" />
                                            <MenuItem Header="_Window" />
                                            <MenuItem Header="_Help" />
                                        </Menu>                                        
                                    </DockPanel>

                                    <!--  Working Frame  -->
                                    <Grid Grid.Row="1">
                                        <Grid.ColumnDefinitions>
                                            <!--  Working section  -->
                                            <ColumnDefinition Width="8*" />
                                            <!--  Result Overview  -->
                                            <ColumnDefinition Width="125" />
                                        </Grid.ColumnDefinitions>
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="9*" />
                                                <RowDefinition Height="9*" />
                                                <RowDefinition Height="{Binding TitleHeightGridLength, FallbackValue=32}" />
                                                <!--  Same like Title height  -->
                                            </Grid.RowDefinitions>
                                            <!--  InputBar  -->
                                            <TabControl Grid.Row="0" Grid.Column="0">
                                                <TabItem Header="General">
                                                    <Label Content="Content goes here..." />
                                                </TabItem>
                                                <TabItem Header="Security" />
                                                <TabItem Header="Details" />
                                            </TabControl>                                            

                                            <StackPanel Grid.Row="2" Orientation="Horizontal">
                                                <Label

                                                    Name="Info"

                                                    Margin="10,2,2,2"

                                                    HorizontalAlignment="Left"

                                                    Content="Info: "

                                                    FontWeight="ExtraBold"

                                                    Foreground="{StaticResource TextStandardBright}" />
                                                <Label

                                                    Name="InfoTexts"

                                                    Width="800"

                                                    Margin="10,2,2,2"

                                                    HorizontalAlignment="Left"

                                                    HorizontalContentAlignment="Left"

                                                    FontWeight="Normal"

                                                    Foreground="{StaticResource TextStandardBright}" />
                                            </StackPanel>
                                        </Grid>
                                        <!--  Results Overview  -->
                                        <StackPanel

                                            Grid.Column="1"

                                            Margin="0,2,2,2"

                                            Background="{StaticResource BackgroundGold}" />
                                    </Grid>
                                </Grid>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <WindowChrome.WindowChrome>
        <WindowChrome

            CaptionHeight="{Binding TitleHeight}"

            CornerRadius="0"

            GlassFrameThickness="0"

            ResizeBorderThickness="{Binding ResizeBorderThickness}" />
    </WindowChrome.WindowChrome



</Window>

推荐答案

Hey folks,

the reason for the described behaviour is found in the WindowChrome property. The CaptionHeight defines the height for i.e. dragging an movong the window.

By setting
Hey folks,
the reason for the described behaviour is found in the WindowChrome property. The CaptionHeight defines the height for i.e. dragging an movong the window.
By setting
WindowChrome.IsHitTestVisibleInChrome="True"

within the control needed to have a clickable behaviour resolves the problem.



My solutuion is:

within the control needed to have a clickable behaviour resolves the problem.

My solutuion is:

<Menu>
                                            <MenuItem Header="_File" WindowChrome.IsHitTestVisibleInChrome="True">
                                                <MenuItem Header="_New..." />
                                                <Separator />
                                                <MenuItem Header="_Open..." />
                                                <Separator />
                                                <MenuItem Header="_Save" />
                                                <MenuItem Header="_Save As..." />
                                                <Separator />
                                                <MenuItem Header="_Exit" />
                                            </MenuItem>
                                            <MenuItem Header="_Edit" WindowChrome.IsHitTestVisibleInChrome="True">
                                                <MenuItem Command="Cut" Header="_Cut" />
                                                <MenuItem Command="Copy" Header="_Copy" />
                                                <MenuItem Command="Paste" Header="_Paste" />
                                            </MenuItem>
                                            <MenuItem Header="_View" WindowChrome.IsHitTestVisibleInChrome="True" />
                                            <MenuItem Header="_Window" WindowChrome.IsHitTestVisibleInChrome="True" />
                                            <MenuItem Header="_Help" WindowChrome.IsHitTestVisibleInChrome="True"/>
                                        </Menu>


这篇关于Wpf菜单栏问题 - menuitem没有出现在rundtime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆