網站首頁 編程語言 正文
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>
原文鏈接:https://www.cnblogs.com/lynn-/p/3262658.html
相關推薦
- 2023-07-02 Pandas數據查詢的集中實現方法_python
- 2022-01-29 寶塔Linux面板的ftp無法使用連接解決方案
- 2023-09-12 django數據庫篩選功能
- 2022-11-15 Python一直報錯SyntaxError:invalid?syntax的解決辦法_python
- 2022-12-14 Jetpack?Compose?DropdownMenu手指跟隨點擊顯示_Android
- 2022-11-01 Python正則表達中re模塊的使用_python
- 2022-04-16 python隊列基本操作和多線程隊列_python
- 2023-12-15 Linux系統——退出vi編輯模式
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支