Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just for reference, the <i>CommandReference</i> class is currently not included in an assembly that you can reference, but is included with the M-V-VM project template. So if you don't build your application from the template, then you have to get the class from somewhere else. I chose to copy it from the sample project. I included it below to allow everyone easy access to this little chunk of goodness, but be sure to check for updates to the template in future versions of the M-V-VM Toolkit. </p> <pre><code>/// &lt;summary&gt; /// This class facilitates associating a key binding in XAML markup to a command /// defined in a View Model by exposing a Command dependency property. /// The class derives from Freezable to work around a limitation in WPF when data-binding from XAML. /// &lt;/summary&gt; public class CommandReference : Freezable, ICommand { public CommandReference( ) { } public static readonly DependencyProperty CommandProperty = DependencyProperty.Register( "Command", typeof( ICommand ), typeof( CommandReference ), new PropertyMetadata( new PropertyChangedCallback( OnCommandChanged ) ) ); public ICommand Command { get { return (ICommand)GetValue( CommandProperty ); } set { SetValue( CommandProperty, value ); } } #region ICommand Members public bool CanExecute(object parameter) { if (Command != null) return Command.CanExecute( parameter ); return false; } public void Execute(object parameter) { Command.Execute( parameter ); } public event EventHandler CanExecuteChanged; private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CommandReference commandReference = d as CommandReference; if (commandReference != null) { ICommand oldCommand = e.OldValue as ICommand; if (oldCommand != null) oldCommand.CanExecuteChanged -= commandReference.CanExecuteChanged; ICommand newCommand = e.NewValue as ICommand; if (newCommand != null) newCommand.CanExecuteChanged += commandReference.CanExecuteChanged; } } #endregion #region Freezable protected override Freezable CreateInstanceCore( ) { return new CommandReference(); } #endregion } </code></pre> <p>Enjoy!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload