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>

 

posted @ 2013-09-14 09:29  wxing67  阅读(2622)  评论(0编辑  收藏  举报