我可以省略 EventTrigger.Actions 吗?

Can I omit the EventTrigger.Actions?

我正在将 WPF 与 MVVM 模式和 Prism 结合使用,并且我正在使用 InteractionRequests 来显示对话框。

当我定义 InteractionTriggers 及其动作时,我这样定义它们:

<i:Interaction.Triggers>
[Other event triggers]
    <i:EventTrigger EventName="Raised" SourceObject="{Binding SomeConfirmationInteractionRequest}">
        <i:EventTrigger.Actions>
            <windowActions:DialogWindowAction />
        </i:EventTrigger.Actions>
    </i:EventTrigger>
</i:Interaction.Triggers>

现在我正在检查我的 EventTriggers,并意识到,我缺少 <i:EventTrigger>:

中的一个 <i:EventTrigger.Actions> 标签
<i:EventTrigger EventName="Raised" SourceObject="{Binding SomeConfirmationInteractionRequest}">
    <windowActions:DialogWindowAction />
</i:EventTrigger>

我更困惑的是我的这部分代码可以工作,而且没有问题。

我的问题:

为什么可以简单地省略?

我可以不写吗?或者离开 EventTrigger.Actions 标签会改变我还没有 realized/experienced 的东西吗?

是的,可以安全地省略它。

如果您查看 TriggerBase class(向上 EventTrigger 的继承树),您会看到它有一个属性 [ContentProperty("Actions")]。这告诉 WPF 将 Actions 属性 视为 XAML.

中元素的直接子元素

这在 WPF 中被广泛使用,例如ContentControls 有 Content 属性(所以你可以写 <Button><Image/></Button> 而不是 <Button><Button.Content><Image/></Button.Content></Button>),Panels 有 Children 属性作为他们的内容等