icommand

Pass command parameter to method in ViewModel in WPF?

孤者浪人 提交于 2019-11-26 17:43:54
问题 I am trying to pass CommandParameter to the method in my ViewModel . How to do this? private void Open(object sender) { if (sender==this.objMainWindow.btnHistory) { objMainWindow.Container.Child = objHistory; } if (sender == this.objMainWindow.btnNew_Item) { objMainWindow.Container.Child = objNewItem; } if (sender == this.objMainWindow.btnSide_Effects) { objMainWindow.Container.Child = objSideEffect; } } This is my meyhod in ViewModel that I want to pass CommandParameter . I use

CanExecuteChanged event of ICommand

只谈情不闲聊 提交于 2019-11-26 16:58:44
问题 Icommand contains two methods and one event. What the two methods do is clear, but I can’t understand what the event does that is provided in ICommand . When is the CanExecuteChanged event raised? The below explanation is on MSDN but I can’t understand it. CanExecuteChanged is raised if the command manager that centralizes the commanding operations detects a change in the command source that might invalidate a command that has been raised but not yet executed by the command binding. Can you

What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?

拈花ヽ惹草 提交于 2019-11-26 12:07:15
问题 I got the following code from Josh Smith\'s MVVM tutorial. Can anyone provide a quick explanation of what this code actually does? public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } I can\'t understand two things: what does the CanExecuteChanged event do? what does the CommandManager.RequerySuggested do? The above code is from the RelayCommand Class from here. 回答1: CanExecuteChanged notifies

Is Josh Smith's implementation of the RelayCommand flawed?

送分小仙女□ 提交于 2019-11-26 09:23:15
问题 Consider the reference Josh Smith\' article WPF Apps With The Model-View-ViewModel Design Pattern, specifically the example implementation of a RelayCommand (In Figure 3). (No need to read through the entire article for this question.) In general, I think the implementation is excellent, but I have a question about the delegation of CanExecuteChanged subscriptions to the CommandManager \'s RequerySuggested event. The documentation for RequerySuggested states: Since this event is static, it

ICommand MVVM implementation

半城伤御伤魂 提交于 2019-11-26 00:28:10
问题 So in this particular MVVM implementation I\'m doing, I need several commands. I really got tired of implementing the ICommand classes one by one, so I came up with a solution, but I don\'t know how good it is, so the input of any WPF expert here will be greatly appreciated. And if you could provide a better solution, even better. What I did is a single ICommand class and two delegates which take an object as a parameter, one delegate is void (for OnExecute), the other bool (for OnCanExecute)