Я хочу привязать метод модели к элементу управления кнопки в шаблоне ListViewItem.Как я могу сделать это в WPF?Я пытался, но я получаю ошибку во время выполнения.
Ошибка ... 
Мне просто нужен очень простой и правильный способ привязать методсобытие нажатия кнопки.Пожалуйста, помогите мне.Я новичок в WPF.
Это мой код .....
<ListView Grid.Row="1"
MaxHeight="500"
Name="entryLisView"
Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="New"
Margin="10,5,0,5"
VerticalAlignment="Top"
HorizontalAlignment="Left" />
<Button Name="cancelThisBtn"
Content="Delete"
Visibility="{Binding ItemCount, Mode=OneWay, Converter={StaticResource EduListItemCancelBtnVisibilityConverter}}"
Grid.Column="1"
Margin="0,5,10,5"
Click="{Binding DeleteDegree}"
VerticalAlignment="Top"
HorizontalAlignment="Right" />
<TextBox wpf:HintAssist.Hint="Exam or Degree Title"
Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
Width="230"
FontSize="18"
Grid.Row="1"
Margin="10,0,10,0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="{Binding Title, Mode=TwoWay}" />
<TextBox wpf:HintAssist.Hint="Subject"
Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
Width="230"
FontSize="18"
Margin="10,0,10,0"
Grid.Row="1"
Grid.Column="1"
Text="{Binding SubjectName, Mode=TwoWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBox wpf:HintAssist.Hint="Institute Name"
Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
Width="230"
FontSize="18"
Margin="10,20,10,0"
Grid.Row="2"
Grid.Column="0"
Text="{Binding InstituteName, Mode=TwoWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBox wpf:HintAssist.Hint="Passing Year"
Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
Width="230"
FontSize="18"
Margin="10,20,10,0"
Grid.Row="2"
Grid.Column="1"
Text="{Binding PassingYear, Mode=TwoWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Это моя модель:
public class Degree : INotifyPropertyChanged
{
private int _id;
private string _title;
private string _instituteName;
private string _subjectName;
private string _passingYear;
private int _itemCount;
public string Title { get { return _title; } set { _title = value; RaisePropertyChanged(); } }
public string InstituteName { get { return _instituteName; } set { _instituteName = value; RaisePropertyChanged(); } }
public string SubjectName { get { return _subjectName; } set { _subjectName = value; RaisePropertyChanged(); } }
public string PassingYear { get { return _passingYear; } set { _passingYear = value; RaisePropertyChanged(); } }
public int Id { get { return _id; } set { _id = value; } }
public int ItemCount { get { return _itemCount; } set { _itemCount = value; RaisePropertyChanged(); } }
public Degree()
{
}
public void DeleteDegree(object sender, RoutedEventArgs e)
{
MessageBox.Show("I got u!");
}
//if (AddNewEducationDialog.Current != null)
//{
// AddNewEducationDialog.Current.degrees.Remove(this);
//}
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged([CallerMemberName]string name = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}