Hello all,
not sure if this is the right place to put this thread on. I hope to get an idea of the following issue:
From a ViewModel I want to call a method in a class different to the calling class but within the same namespace, as below:
The method is invoked by a button click action in the View
I have no idea how to set the CommandParameter in oder to get the instance of the ModelView transferred to the method.
Any hint is much appreciated.
Matthias
not sure if this is the right place to put this thread on. I hope to get an idea of the following issue:
From a ViewModel I want to call a method in a class different to the calling class but within the same namespace, as below:
C#:
namespace WpfApp8
{
class ViewModel : INotifyPropertyChanged
{
...
public ViewModel()
{
ActionCommand = new MyCommand(this);
ActionCommand.CanExecuteFunc = obj => true;
//ActionCommand.ExecuteFunc = MyActionFunc;
ActionCommand.ExecuteFunc = MyClass.MyActionFunc ;
}
private string myname;
public string myName
{
get => myname;
set { myname = value; OnPropertyChanged(); }
}
...
}
public class MyClass
{
public static void MyActionFunc(object param)
{
_ = MessageBox.Show("Parameter: " + (string)param);
param.myName = "Fred";
}
}
}
The method is invoked by a button click action in the View
View:
<Button
Command="{Binding Path=ActionCommand }"
CommandParameter="{ ?? }"
Grid.Column="1" Grid.Row="2">
Click
</Button>
I have no idea how to set the CommandParameter in oder to get the instance of the ModelView transferred to the method.
Any hint is much appreciated.
Matthias