WPF-后台代码使用Behavior

xaml里面使用很简单

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"


 
    
 

 

后台代码使用

Microsoft.Xaml.Behaviors.Layout.MouseDragElementBehavior mouseDragElementBehavior = new Microsoft.Xaml.Behaviors.Layout.MouseDragElementBehavior();
Microsoft.Xaml.Behaviors.Interaction.GetBehaviors(ElementName).Add(mouseDragElementBehavior);

 

 

加上触发器

xaml

"TextBoxInvoker" Text="TextBox" >
    
        "KeyDown" >
            "TargetedButton" />
        
    

后台代码

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);

 

你可能感兴趣的:(WPF-后台代码使用Behavior)