WPF 事件觸發命令

方法一使用mvvmlight:mvvm

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>

方法二:spa

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>
相關文章
相關標籤/搜索