日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

Interaction triggers in WPF

發(fā)布時(shí)間:2023/12/3 asp.net 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Interaction triggers in WPF 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
 Interaction triggers in WPF

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

當(dāng)不足以使用ICommand的時(shí)候,這種特殊的手段對(duì)MVVM模式非常有用。

我們需要在我們的項(xiàng)目中添加兩個(gè)引用:

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

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

  在UserControl添加兩個(gè)特性

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中創(chuàng)建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>

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

?

附錄:使用ICommand的例子。

//區(qū)別:這樣可以傳參數(shù),但是綁定的是實(shí)現(xiàn)了ICommand接口的類(lèi)的對(duì)象。//步驟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>

總結(jié)

以上是生活随笔為你收集整理的Interaction triggers in WPF的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。