WPF 事件触发命令

原文: WPF 事件触发命令

方法一使用mvvmlight:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"

<i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <cmd:EventToCommand Command="{Binding HandleCommand}" CommandParameter="LoadItems"/>
        </i:EventTrigger>
</i:Interaction.Triggers>

方法二:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

<i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding HandleCommand}" CommandParameter="LoadItems" />
        </i:EventTrigger>
        <i:EventTrigger EventName="Unloaded">
            <i:InvokeCommandAction Command="{Binding HandleCommand}" CommandParameter="Unload" />
        </i:EventTrigger>
 </i:Interaction.Triggers>

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/9274733.html