commandbinding

How to bind Close command to a button

牧云@^-^@ 提交于 2019-11-27 10:31:32
The easiest way is to implement ButtonClick event handler and invoke Window.Close() method, but how doing this through a Command binding? Nir I think that in real world scenarios a simple click handler is probably better than over-complicated command-based systems but you can do something like that: using RelayCommand from this article http://msdn.microsoft.com/en-us/magazine/dd419663.aspx public class MyCommands { public static readonly ICommand CloseCommand = new RelayCommand( o => ((Window)o).Close() ); } <Button Content="Close Window" Command="{X:Static local:MyCommands.CloseCommand}"

Application Level shortcut keys in WPF

有些话、适合烂在心里 提交于 2019-11-27 06:54:35
问题 In WPF application I am currently trying to bind a Command to launch a calculator Tool form any where in the application using shortcut keys, I have created a command but not getting how to map commands and shortcut keys to create universal shortcut keys in my application. Thanks in advance. 回答1: You can do this in xaml - see the example in the documentation for the KeyBinding class: <Window.InputBindings> <KeyBinding Command="ApplicationCommands.Open" Gesture="CTRL+R" /> </Window

WPF - How to force a Command to re-evaluate 'CanExecute' via its CommandBindings

泄露秘密 提交于 2019-11-27 02:54:57
I have a Menu where each MenuItem in the hierarchy has its Command property set to a RoutedCommand I've defined. The associated CommandBinding provides a callback for the evaluation of CanExecute which controls the enabled state of each MenuItem . This almost works. The menu items initially come up with the correct enabled and disabled states. However when the data that my CanExecute callback uses changes, I need the command to re-request a result from my callback in order for this new state to be reflected in the UI. There do not appear to be any public methods on RoutedCommand or

WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?

吃可爱长大的小学妹 提交于 2019-11-26 22:06:07
(Note - this is a re-post as my first question got posted under wrong headline: Here Sorry!) I have a standard WPF treeview and have bound items to view model classes. I now wish to handle behaviour when items are double-clicked (opening documents visual-studio-style). I can get event-handler to fire in the control housing the treeview (xaml shown), but how do I bind to specific behaviour on the view model classes - e.g. ProjectViewModel? Preferable bound to ICommand-implementer, as this is used elsewhere... <TreeView ItemsSource="{Binding Projects}" MouseDoubleClick="TreeView_MouseDoubleClick

How to bind Close command to a button

你说的曾经没有我的故事 提交于 2019-11-26 17:57:07
问题 The easiest way is to implement ButtonClick event handler and invoke Window.Close() method, but how doing this through a Command binding? 回答1: I think that in real world scenarios a simple click handler is probably better than over-complicated command-based systems but you can do something like that: using RelayCommand from this article http://msdn.microsoft.com/en-us/magazine/dd419663.aspx public class MyCommands { public static readonly ICommand CloseCommand = new RelayCommand( o => (

WPF - How to force a Command to re-evaluate &#39;CanExecute&#39; via its CommandBindings

依然范特西╮ 提交于 2019-11-26 10:17:22
问题 I have a Menu where each MenuItem in the hierarchy has its Command property set to a RoutedCommand I\'ve defined. The associated CommandBinding provides a callback for the evaluation of CanExecute which controls the enabled state of each MenuItem . This almost works. The menu items initially come up with the correct enabled and disabled states. However when the data that my CanExecute callback uses changes, I need the command to re-request a result from my callback in order for this new state