views:

239

answers:

3

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>
A: 

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

Andrew Shepherd
I think you misunderstood my question, I want to set a Blend Behavior on a Style.
Jobi Joy
A: 

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.

Jobi Joy
A: 

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.

Mark Smeltzer