自定义路由事件失败!

时间:2009-12-19 21:12:42

标签: wpf routedevent

我的应用程序如下所示:

1 Window
  2 Frame
    3 Page  
      4 Control

在Control(4)中我有一个自定义路由事件,我希望Frame(2)能够处理。

活动:

    public static readonly RoutedEvent PreviewArtistLinkClickedEvent = EventManager.RegisterRoutedEvent(
         "PreviewArtistLinkClicked", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(Hyperlink));


    public event RoutedEventHandler PreviewAlbumLinkClicked {
        add { AddHandler(PreviewAlbumLinkClickedEvent, value); }
        remove { RemoveHandler(PreviewAlbumLinkClickedEvent, value); }
    }

    void RaisePreviewArtistLinkClickedEvent(object sender, RoutedEventArgs e) {
        RoutedEventArgs eventArgs = new RoutedEventArgs(Tracklist.PreviewArtistLinkClickedEvent);
        RaiseEvent(eventArgs);
    }

框架XAML:

            <Frame Name="frameContent" Grid.Column="1" Background="#373737"  NavigationUIVisibility="Hidden"
               gui:Tracklist.PreviewArtistLinkClicked="frameContent_PreviewArtistLinkClicked"/>

编译好但发生了这种情况:

  

找不到名为'PreviewArtistLinkClicked'的属性的DependencyProperty或PropertyInfo。

1 个答案:

答案 0 :(得分:0)

请参阅PreviewArtistLinkClickedEvent的OwnerType,在您的情况下是超链接,就我从您的代码中获取的情况而言,此案例中的OwnerType应为TrackList 所以你的代码看起来像这样:

public static readonly RoutedEvent PreviewArtistLinkClickedEvent = EventManager.RegisterRoutedEvent(
     "PreviewArtistLinkClicked", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(TrackList));

希望这会有所帮助!!