WPF如何绑定到ICommand.CanExecute()

基本来说,我遇到的问题与WPF - how to hide menu item if command's CanExecute is false?非常相似,被接受的答案使用了一种巧妙的解决方法来绑定到IsEnabled而不是CanExecute()的结果。 las IsEnabled解决方法在我的情况下不起作用
KeyBinding事件期间,我从各种控件收集了PreviewGotKeyboardFocus的集合,因此,我无法确定是否由于其他原因(例如{{ 1}}绑定),甚至根本不禁用该元素(例如,IsBeingLoaded如果无法执行其Grid也不会禁用)。如何绑定到KeyBinding的当前KeyBinding.Command值?

CanExecute()

public class ContextHelperVM : ViewModelBase { public ObservableCollection<KeyBinding> ContextEffectiveKeybindings { get; } // KeyBinding list loading,maintaining,etc. pseudocode // Keybindings = FocusedElement.TraverseToParentWidnow().GatherKeyBindings(); } 中,我想将不透明度设置为不可执行的ContextHelperView.xaml

KeyBindings

如何修复代码,以便为无法执行的<ItemsControl ItemsSource="{Binding ContextEffectiveKeybindings}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Key}"/> <DataTemplate.Triggers> <DataTrigger Binding="{Binding Command.????}" Value="False"><!--how to bind here??--> <Setter Property="Opacity" Value="0.5"> <DataTrigger> </DataTemplate.Triggers> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> s正确设置不透明度?

qq11479366 回答:WPF如何绑定到ICommand.CanExecute()

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2759483.html

大家都在问