I have the following ViewModel:
public class ViewModel : INotifyPropertyChanged {
public ObservableCollection<A> MyCollection { get; set; }
public RelayCommand Command1{ get; set; }
public ViewModel() {
Command1= new RelayCommand(Method1);
}
void Method1() {
...
}
}
And this View:
<UserControl x:Class="TemplateEditor.Views.View"
xmlns:vm="clr-namespace:TemplateEditor.ViewModels"
DataContext="{DynamicResource ViewModel}">
<UserControl.Resources>
<vm:ViewModel x:Key="ViewModel"/>
</UserControl.Resources>
...
<Button DataContext="{StaticResource FormIdBlockViewModel}" Content="qwe" Command="{Binding Command1}" />
...
</UserControl>
The button works fine in this case, but I want to move all commands into a certain file. So, if I create AppCommands.cs file:
public class AppCommands
{
private static RelayCommand Command1 { get; set; }
static AppCommands()
{
Command1 = new RelayCommand(Method1);
}
public static void Method1(object parameter)
{
....
}
}
Also, I change View:
...
xmlns:commands="clr-namespace:TemplateEditor.Common"
...
<UserControl.Resources>
<vm:ViewModel x:Key="ViewModel"/>
<commands:AppCommands x:Key="AppCommands"/>
...
<Button DataContext="{StaticResource AppCommands}" Content="qwe" Command="{Binding Command1}" />
The command does not work.
Could you please to advise how to perform binding to AppCommands.Commands
?