它是正确的事件+ DependencyProperty?

时间:2010-11-20 21:38:45

标签: .net wpf events wpf-controls

    // Property
    IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(MyControl),new UIPropertyMetadata(false, 
        new PropertyChangedCallback(OnIsSelectedChanged)));

    // Event
    public event RoutedEventHandler SelectedChanged
    {
        add { AddHandler(SelectedChangedEvent, value); }
        remove { RemoveHandler(SelectedChangedEvent, value); }
    }

    // How Do I Raise the Event ???
    static void OnIsSelectedChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
    {
        var s = (MyControl)source;

        // ???? 
        s.OnSelectedChanged(source, EventArgs.Empty);

1 个答案:

答案 0 :(得分:0)

如果您要筹集RoutedEvent,请致电this.Raise(...);

如果您使用静态方法调用,请按以下方式调用它:

((MyControl)s).Raise( new RoutedEventArg( MyControl.MyEvent ) );