I have crated a Blend behavior for Button. How can I set that to all of my Buttons in the app.
<Button ...>
<i:Interaction.Behaviors>
<local:MyBehavior />
</i:Interaction.Behaviors>
</Button>
I have crated a Blend behavior for Button. How can I set that to all of my Buttons in the app.
<Button ...>
<i:Interaction.Behaviors>
<local:MyBehavior />
</i:Interaction.Behaviors>
</Button>
Add the style to the app.xaml file, under <Application.Resources>.
Do not assign your Style a key, but instead set "TargetType=Button"
<Application.Resources>
<Style TargetType="Button">
<!-- Add Setters Here -->
</Style>
</Application.Resources>
This will then apply to all Buttons in your application, (with the exception of the ones that have their "OverrideDefaultStyle" property set to true.)
Behavior code expects a Visual, so we can add it only on a visual. So the only option I could see is to add to one of the element inside the ControlTemplate so as to get the behavior added to the Style and affect on all the instance of a particular control.
You might be interested in the technique I published on my blog (http://www.livingagile.com/Blog/July-2010/Attaching-Behaviors-from-the-Expression-Blend-SDK-) for assigning behaviors using styles.