WPF(XAML, XBAP, .Net3.5)GUIプログラミング Part5at TECH
WPF(XAML, XBAP, .Net3.5)GUIプログラミング Part5 - 暇つぶし2ch752:デフォルトの名無しさん
10/05/01 10:52:45
2010を使い.NET4でWPFを始めてみました
ググりながら試行錯誤してコマンドとコンテキストメニューを繋ごうとしています
キー操作だと正常に動作し、PlayPause_Executeが呼ばれるのですが、
コンテキストメニューは見出しやキーの表示は合っていますが、グレー表示のままで選択できません
何が悪いのでしょうか?

タイマで定期的にCommandManager.InvalidateRequerySuggested();してみても変わらないようですし
キーを押したときにはCheckCanExecuteCommandが呼ばれますが、それ以外では呼ばれないようです

public class Commands
{
public static RoutedUICommand PlayPause = new RoutedUICommand("再生/一時停止", "PlayPause", typeof(Commands),
new InputGestureCollection { new KeyGesture(Key.Space) });
}

XAMLで(はしょっています)
<Window xmlns:local="clr-namespace:hoge">
<StatusBar.ContextMenu>
<ContextMenu>
<MenuItem Command="{x:Static local:Commands.PlayPause}" IsEnabled="True" />
</ContextMenu>
</StatusBar.ContextMenu>

C#側コンストラクタで
CommandBindings.Add(new CommandBinding(Commands.PlayPause, PlayPause_Execute, CheckCanExecuteCommand));

private void CheckCanExecuteCommand(Object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = true;
}



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch