0

MenuItem List があり、切り取り、コピー、貼り付けなどの ApplicationCommnds を使用しています。コマンドが無効になっているときに何らかの処理を実行したいのですが、スタイルが機能していません。私の場合は機能しません。したがって、明示的に設定しようとします。

<TextBox x:Name="AssignmentTextBox" >
    <TextBox.ContextMenu>
        <ContextMenu Background="White">
            <MenuItem Command="ApplicationCommands.Undo" Style="StaticResource _MenuItem}"/>                                 
            <Separator />
            <MenuItem Command="ApplicationCommands.Cut"   Style="{StaticResource _MenuItem}"/>
            <MenuItem Command="ApplicationCommands.Copy"  Style="{StaticResource _MenuItem}" />
            <MenuItem Command="ApplicationCommands.Paste"  Style="{StaticResource _MenuItem}"/>                                    
            <Separator  />
            <MenuItem Command="ApplicationCommands.SelectAll"  Style="{StaticResource _MenuItem}"/>
        </ContextMenu>
    </TextBox.ContextMenu>
</TextBox>
4

2 に答える 2

1

とった。最初の MenuItem の Style プロパティの値を設定するときに、括弧{がありませんでした。

なにが問題ですか

<MenuItem Command="ApplicationCommands.Undo" Style="StaticResource _MenuItem}"/> 

何が正しいか

<MenuItem Command="ApplicationCommands.Undo" Style="{StaticResource _MenuItem}"/> 

[編集済み]以下のテスト ケースでは、有効な MenuItems は緑になり、無効な MenuItems は赤になります。これが問題の解決に役立つことを願っています

<ContextMenu Background="White">
       <ContextMenu.Resources>
            <Style x:Key="_MenuItem1" TargetType="{x:Type MenuItem}">
                   <Style.Triggers>
                          <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled}" Value="false">
                              <Setter Property="Foreground" Value="Red"/>
                          </DataTrigger>
                          <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled}" Value="True">
                              <Setter Property="Foreground" Value="Green"/>
                          </DataTrigger>
                    </Style.Triggers>
            </Style>
      </ContextMenu.Resources>
      <MenuItem Command="ApplicationCommands.Undo" Style="{StaticResource _MenuItem1}"/>
      <Separator />
      <MenuItem Command="ApplicationCommands.Cut"   Style="{StaticResource _MenuItem1}"/>
      <MenuItem Command="ApplicationCommands.Copy"  Style="{StaticResource _MenuItem1}" />
      <MenuItem Command="ApplicationCommands.Paste"  Style="{StaticResource _MenuItem1}"/>
      <Separator  />
      <MenuItem Command="ApplicationCommands.SelectAll"  Style="{StaticResource _MenuItem1}"/>
  </ContextMenu>

スクリーンショット

ここに画像の説明を入力

于 2013-02-07T13:58:22.510 に答える
0

MenuItem テンプレートを変更するか、フォアグラウンドをオーバーライドして、CommandCan の実行が適切な視覚要素を更新してグレー色の「無効」としてレンダリングできないようにしたようです。

テンプレートまたは _MenuItem をキーにしたスタイルを見せていただけないでしょうか。

于 2013-02-08T09:47:51.777 に答える