command - RaiseCanExecuteChanged more convenience -
i'd raisecanexecutechanged when canexecute condition got changed. e.g.:
public class viewmodel { public viewmodel() { command = new relaycommand(action,condition); } private bool condition() { return this.condition1&&this.condition2&&this.condition3; } public bool condition1 { get{...} set{.... **command.raisecanexecutechanged();}** } public bool condition2 { get{...} set{.... command.**raisecanexecutechanged();}** } public bool condition3 { get{...} set{.... **command.raisecanexecutechanged();}** }
}
that works fine. don't write many raisecanexecutechanged, want set these changes automatically. e.g in relaycommand, create new method named raisechanged
public void raisechanged(xxxxxx xxx, params string[] propertynames) { // each property in propertynames, // raisecanexecutechanged(); }
i put viewmodel vm parameters, , use vm.propertychanged+=(s,e)=>{} don't think it's way this.
does have other ideas?
i develop solution can that:
c# view model:
public bool canexecutemethod(object sender) { } public void buttonexecutemethod(object sender) { } public event action eventnotifycanexecutechanged; private action _delegatenotifycanexecutechanged; public action delegatenotifycanexecutechanged { { return _delegatenotifycanexecutechanged; } set { _delegatenotifycanexecutechanged = value; } } public void canexecuteflag { if (eventnotifycanexecutechanged != null) { eventnotifycanexecutechanged(); } if (_delegatenotifycanexecutechanged != null) { _delegatenotifycanexecutechanged();} }
xaml:
< button content="button cmd-excech" horizontalalignment="left" margin="27,231,0,0" verticalalignment="top" width="120" command="{mark:bindcommandresource mainwindowviewmodel, executemethodname=buttonexecutemethod, canexecutemethodname=canexecutemethod, eventtoinvokecanexecutechanged=eventnotifycanexecutechanged, propertyactioncanexecutechanged=delegatenotifycanexecutechanged}" />
i put/share solution in open source project mvvm-wpf xaml mark-up binding extensions - http://wpfmvvmbindingext.codeplex.com
Comments
Post a Comment