0

使用此代码,我向 RootFrame.Obscured 添加了一个事件处理程序。

(Application.Current as App).RootFrame.Obscured += onObScured;

由于可以从 App 中的每个类访问 RootFrame,如果我添加来自不同类的不同事件处理程序会发生什么?例子:

class A{
    (Application.Current as App).RootFrame.Obscured += onObScuredA;

    private void onObScuredA(object sender, ObscuredEventArgs e) {
        //Some code here
    }
}

class B{
    (Application.Current as App).RootFrame.Obscured += onObScuredB;

    private void onObScuredB(object sender, ObscuredEventArgs e) {
        //Some other code here
    }
}

当事件被触发时,如果A和B都创建了一个实例,是否会同时触发onObScuredA()和onObScuredB()?在 App.xaml.cs 类上添加事件处理程序及其各自的方法是否正确,以便我可以确定添加了哪些事件处理程序?

谢谢。

4

1 回答 1

1

您可以根据需要将任意数量的事件处理程序添加到事件中,它们都会被调用。这就是事件的本质,当它们触发时,所有事件处理程序都会处理此事件。

所以,答案是“它们都会被触发”。现在,这可能是也可能不是您想要的,但是添加新的事件处理程序不会替换以前的事件处理程序。

在 MSDN 上阅读更多内容:处理和引发事件

于 2013-09-12T09:24:23.347 回答