xaml裡面使用很簡單 xmlns:i="http://schemas.microsoft.com/xaml/behaviors" <i:Interaction.Behaviors> <i:MouseDragElementBehavior/> </i:Interaction.Behaviors> 後 ...
xaml裡面使用很簡單
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" <i:Interaction.Behaviors> <i:MouseDragElementBehavior/> </i:Interaction.Behaviors>
後臺代碼使用
Microsoft.Xaml.Behaviors.Layout.MouseDragElementBehavior mouseDragElementBehavior = new Microsoft.Xaml.Behaviors.Layout.MouseDragElementBehavior();
Microsoft.Xaml.Behaviors.Interaction.GetBehaviors(ElementName).Add(mouseDragElementBehavior);
加上觸發器
xaml
<TextBox x:Name="TextBoxInvoker" Text="TextBox" > <i:Interaction.Triggers> <i:EventTrigger EventName="KeyDown" > <behavior:TextBoxEnterButtonInvoke TargetName="TargetedButton" /> </i:EventTrigger> </i:Interaction.Triggers> </TextBox>
後臺代碼
TextBoxEnterButtonInvoke textBoxEnterButtonInvoke = new TextBoxEnterButtonInvoke(); textBoxEnterButtonInvoke.TargetName = "TargetedButton"; System.Windows.Interactivity.EventTrigger eventTrigger = new System.Windows.Interactivity.EventTrigger("KeyDown"); eventTrigger.Actions.Add(textBoxEnterButtonInvoke); System.Windows.Interactivity.Interaction.GetTriggers(TextBoxInvoker).Add(eventTrigger);