標籤:text 引入 activity tar assembly .com windows trigger cti
下載System.Windows.Interactivity.dll檔案,並引入項目中(在VS項目的引用列表中可以看到)。
XAML中使用該dll
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<!-- TextBox控制項的獲得焦點、失去焦時間點事件 --><TextBox Text="Test"> <i:Interaction.Triggers> <i:EventTrigger EventName="LostFocus"> <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.OnTextLostFocus}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type TextBox}}}"/> </i:EventTrigger> <i:EventTrigger EventName="GotFocus"> <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.OnTextGotFocus}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type TextBox}}}"/> </i:EventTrigger> </i:Interaction.Triggers></TextBox>
由於VS中不支援System.Windows.Interactivity的智能提示,經常要查閱這個EventTrigger還能觸發哪些方法,所有EventName的列表如下:
- MSDN中Grid Events https://msdn.microsoft.com/en-us/library/system.windows.controls.grid_events(v=vs.110).aspx
【WPF/WAF】使用System.Windows.Interactivity互動事件