日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Interaction triggers in WPF

發布時間:2023/12/3 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Interaction triggers in WPF 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
 Interaction triggers in WPF

Interaction Class?- static class that owns the Triggers and Behaviors attached properties. Handles propagation of AssociatedObject change notifications (MSDN).

當不足以使用ICommand的時候,這種特殊的手段對MVVM模式非常有用。

我們需要在我們的項目中添加兩個引用:

- Microsoft.Expression.Interactions.dll
- System.Windows.Interactivity.dll

代碼例子:
?1)引用Microsoft.Expression.Interactions.dll和System.Windows.Interactivity.dll

  在UserControl添加兩個特性

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" <!--或者--> xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"

?2) 在ViewModel中創建public方法

public void SubmitClicked(){MessageBox.Show("Button was clicked");}

?3) 在UserControl中添加button到Xaml

<Button Content="Submit Method" Width="180"><i:Interaction.Triggers><i:EventTrigger EventName="Click"><ei:CallMethodAction TargetObject="{Binding}" MethodName="SubmitClicked"/></i:EventTrigger></i:Interaction.Triggers> </Button>

如果我們想在這個方法中使用參數,我們應該在ViewModel中使用屬性(例如雙向綁定)。

?

附錄:使用ICommand的例子。

//區別:這樣可以傳參數,但是綁定的是實現了ICommand接口的類的對象。//步驟1:引用System.Windows.Interactivity.dll,添加特性。xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" //步驟2:使用。  <i:Interaction.Triggers><i:EventTrigger EventName="Loaded"><i:InvokeCommandAction Command="{Binding ClockWindowLoadCommand}" CommandParameter="{Binding ElementName=txtCardNo}"/></i:EventTrigger><i:EventTrigger EventName="KeyUp"><i:InvokeCommandAction Command="{Binding WindowKeyCommand}"/></i:EventTrigger><i:EventTrigger EventName="Activated"><i:InvokeCommandAction Command="{Binding WindowActivatedCommand}" CommandParameter="{Binding ElementName=txtCardNo}"/></i:EventTrigger> </i:Interaction.Triggers>

總結

以上是生活随笔為你收集整理的Interaction triggers in WPF的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。