请你解释一下,为什么我编译程序时会出现这个错误?
这个例子来自一本书。
代码c#:
private void lst_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (lst.SelectedItem == null) return;
txtSelection.Text = String.Format(
"You chose item at position {0}.\r\nChecked state is {1}.",
lst.SelectedIndex,
((CheckBox)lst.SelectedItem).IsChecked);
}
代码xaml:
<ListBox Name="lst" SelectionChanged="lst_SelectionChanged"
CheckBox.Click="lst_SelectionChanged">
<CheckBox Margin="3">Option 1</CheckBox>
<CheckBox Margin="3">Option 2</CheckBox>
<TextBox Name="txtSelection" Width="200" ></TextBox>
</ListBox>
这是错误:
"No overload for 'lst_SelectionChanged' matches delegate 'System.Windows.Input.MouseButtonEventHandler'"
答案 0 :(得分:0)
将XAML更改为以下内容:
<ListBox Name="lst" SelectionChanged="lst_SelectionChanged">
<CheckBox Margin="3">Option 1</CheckBox>
<CheckBox Margin="3">Option 2</CheckBox>
<TextBox Name="txtSelection" Width="200" ></TextBox>
</ListBox>