在样式中设置事件处理程序

Set event handlers in styles

在 WPF 中,我们可以使用 Style 中的 EventSetter 轻松设置事件处理程序。为什么它没有移植到 Universal Windows Apps?以及如何解决此限制?

您可以改用 Behaviors SDKEventTriggerBehavior 部分,它现在内置于 Visual Studio 2013,

<Button Content="Click" VerticalAlignment="Center" HorizontalAlignment="Center" >
        <interactivity:Interaction.Behaviors>
               <core:EventTriggerBehavior EventName="Click">
                  <core:InvokeCommandAction Command="{Binding ClickCommand}" CommandParameter="{Binding}"/>
               </core:EventTriggerBehavior>
        </interactivity:Interaction.Behaviors>
</Button>

现在在 Windows 通用应用程序中,您可以将行为下载为 nuget 包。 https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Uwp.Managed/

来源: https://blogs.windows.com/buildingapps/2015/11/30/xaml-behaviors-open-source-and-on-uwp/