0

Visual Studio 的 C# 编译器提示一个没有基础的错误:“'ItemSelection' 没有重载与 MainPage.xaml 中的委托 'OnItemSelected' 匹配”(或者我是盲人,看不到错误)尽管有错误出现的事实,但现在没有(奇怪的是)。感谢您的帮助。

//MainPage.xaml
<ListBox.ItemTemplate>
    <DataTemplate>
        <local:WordBlock   Word="{Binding}" OnSlideOccured="OnSlide"  OnItemSelection="ItemSelection"/>
    </DataTemplate>
</ListBox.ItemTemplate>
//MainPage.xaml.cs
private void ItemSelection(string word)
{
    ToSearch = word;
    (Panorama.Items[0] as PanoramaItem).Visibility = Visibility.Collapsed;
    Panorama.SetValue(Panorama.SelectedItemProperty, Panorama.Items[0]);
    Panorama.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
    (Panorama.Items[0] as PanoramaItem).Visibility = Visibility.Visible;
}
//WordBlock.xaml.cs
public delegate void OnItemSelected(string word);
public event OnItemSelected OnItemSelection;

4

1 回答 1

0

显然,xaml 中使用的事件需要对象类型的第一个参数。将代表更改为:

public delegate void OnItemSelected(object sender,string word);

和处理程序:

private void ItemSelection(object sender,string word)

似乎解决了编译问题(或者您可以仅用EventHandler<string>作事件类型)。

于 2013-09-24T19:12:54.300 回答