проблемы с командами wpf. Не работают команды mvvm
RelayCommand
public class RelayCommand : ICommand
{
private Action<object> execute;
private Func<object, bool> canExecute;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return this.canExecute == null || this.canExecute(parameter);
}
public void Execute(object parameter)
{
this.execute(parameter);
}
}
OneMoreViewModel
public class RelayCommand : ICommand
{
private Action<object> execute;
private Func<object, bool> canExecute;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return this.canExecute == null || this.canExecute(parameter);
}
public void Execute(object parameter)
{
this.execute(parameter);
}
}
View
<ListBox Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
BorderThickness="0" RenderTransformOrigin="0.5,0.5" SelectedItem="{Binding SelectedArticle}"
ItemsSource="{Binding Articles_list}" Grid.Row="3" VerticalAlignment="Top" Height="550"
Grid.ColumnSpan="2" HorizontalAlignment="Left" Width="616" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="151" Height="221" Margin="20 30 20 20">
<Button Command="{Binding RemoveCommand}" CommandParameter="{Binding}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
MainViewModel
public static ObservableCollection<NewArticlesViewModel> articles_list { get; set; }
public MainViewModel()
{
articles_list = new ObservableCollection<NewArticlesViewModel>();
Articles_list = b.GetArticles();
}
public ObservableCollection<NewArticlesViewModel> Articles_list
{
get { return articles_list; }
set
{
articles_list = value;
OnPropertyChanged("Articles_list");
}
}