現時点ではまだWPFをいじっていますが、このコンテキストメニュー項目が無効になっている理由がわかりません。
<Window x:Class="DisabledMenuItemProblem.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DisabledMenuItemProblem"
Title="Window1" Height="300" Width="300">
<TextBlock Text="fooooobaaaaaar">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Foo" Command="{x:Static local:MyCommands.FooBar}" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</Window>
using System.Windows;
using System.Windows.Input;
namespace DisabledMenuItemProblem
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
CommandBindings.Add(new CommandBinding(MyCommands.FooBar, FooExecuted, CanFooExecute));
}
public void FooExecuted(object sender, ExecutedRoutedEventArgs e)
{ MessageBox.Show("Foo!"); }
public void CanFooExecute(object sender, CanExecuteRoutedEventArgs e)
{ e.CanExecute = true; }
}
public static class MyCommands
{
public static RoutedCommand FooBar = new RoutedCommand();
}
}
私は何が欠けていますか?
また、私を困惑させているのは、ウィンドウにボタンを投げてそのコマンドをFooBarに設定すると、それが機能し、実行されると、コンテキストメニューが有効になることです。
乾杯、クリス。