我创建了以下用户控件:
public partial class ReplacementPatternEditor : UserControl, INotifyPropertyChanged
{
....
public static readonly RoutedEvent CollectionChanged = EventManager.RegisterRoutedEvent(
"CollectionChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ReplacementPatternEditor));
void RaiseCollectionChangedEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(ReplacementPatternEditor.CollectionChanged);
RaiseEvent(newEventArgs);
}
...
}
现在,当我尝试在我的 xaml 代码中使用此路由事件时:
<local:ReplacementPatternEditor ItemsSource="{Binding MyItemSource}" CollectionChanged="OnCollectionChanged"/>
我在编译时遇到以下错误:
The property 'CollectionChanged' does not exist in XML namespace 'clr-namespace:MyNamespace'
为什么我会得到这个,以及如何使路由事件起作用?