WPF(XAML, XBAP, .Net ..
752:デフォルトの名無しさん
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
5356日前に更新/192 KB
担当:undef