In Xaml, I can put custom behavior for a text field, for example:
<TextBox> <i:Interaction.Behaviors> <My:TextBoxNewBehavior/> </i:Interaction.Behaviors> </TextBox>
I want all TextBox to have this behavior, so how do I put this behavior in an implicit style, for example?
<Style TargetType="TextBox"> <Setter Property="BorderThickness" Value="1"/> .... </Style>
Update: Thanks for the info. Try the method suggested below and the application crashes:
<Setter Property="i:Interaction.Behaviors"> <Setter.Value> <My:TextBoxNewBehavior/> </Setter.Value> </Setter>
My behavior is something like:
public class TextBoxMyBehavior : Behavior<TextBox> { public TextBoxMyBehavior() { } protected override void OnAttached() { base.OnAttached(); AssociatedObject.KeyUp += new System.Windows.Input.KeyEventHandler(AssociatedObject_KeyUp); } void AssociatedObject_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Enter) {
TextBoxMyBehavior does not look the same as in intelligence.
source share