Hey I have created a microsoft Ribbon Window in Visual studio 2010 wich works great with databinding in a one way manner.
So if I push a button a method get's triggered and the code inside get's executed, it even works with passing a parameter, now my question is how I should return a value of a method to a textbox,treeview or other control on the RibbonWindow?
I'm using this relay command class:
public class RelayCommand: ICommand { #region Fields readonly Action<object> _execute; readonly Predicate<object> _canExecute; #endregion // Fields #region Constructors /// <summary> /// Creates a new command that can always execute. /// </summary> /// <param name="execute">The execution logic.</param> public RelayCommand(Action<object> execute) : this(execute, null) { } /// <summary> /// Creates a new command. /// </summary> /// <param name="execute">The execution logic.</param> /// <param name="canExecute">The execution status logic.</param> public RelayCommand(Action<object> execute, Predicate<object> canExecute) { if (execute == null) throw new ArgumentNullException("execute"); _execute = execute; _canExecute = canExecute; } #endregion // Constructors #region ICommand Members public bool CanExecute(object parameters) { return _canExecute == null ? true : _canExecute(parameters); } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameters) { _execute(parameters); } #endregion // ICommand Members } }
And than I have an other class with ICommands and methods.
like this: How can I return the param value from method ConnectionStartUp to a textbox control for example?
public class MyInputCommands { private ICommand _connectionStartUpCommand; private Connection connectie; public ICommand ConnectionStartUpCommand { get { if (_connectionStartUpCommand == null) { _connectionStartUpCommand = new RelayCommand( param => this.ConnectionStartUp(param), param => this.CanDoIt() ); } return _connectionStartUpCommand; } } public string ConnectionStartUp(Object param) { MessageBox.Show("De status van deze Checkbox is: hello world" + param); return param } private bool CanDoIt() { //Nagaan of het command kan worden uitgevoerd. return true; } }Also is it possible to pass more than one param (for example values of three textboxcontrols?