views:

38

answers:

2

I'm looking for an easy way to set ClickMode="Pressed" on every Control in my Silverlight Application (that inherits from ButtonBase obviously).

The solution should also access any ButtonBase-Control that is part of a controltemplate like ComboBox of SilverlightToolkit.

Do i have to create a custom theme for this? If yes, how do i reuse an existing theme and just override this property?

Thanks in advance.

A: 

You actually answered your own question. Yes you can use an existing style to ensure the ClickMode property is set on every ButtonBase control in your app. Here is a style that will get you going. This is an un-named style which will ensure that any control that extends from ButtonBase will inherit this style.

 <Style TargetType="ButtonBase">
        <Setter Property="ClickMode" Value="Pressed"/>
 </Style>

I hope this helps.

dParker
thanks for your answer. Where do you put this? i tried this before in the <UserControl.Resources> tag and it didnt work. btw: i just noticed the mode is actually called "Press"
Chris
You can put it in the <UserControl.Resources> tag, but if you want the style to apply to all controls in the application (not just a particular user control) then use a Resource Dictionary and reference it in the App.xaml fileThis post should clarify any questions you have about styles in silverlight.http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx
dParker
i have now used an external ressource dictionary which gets loaded at Application Startup but TargetType=ButtonBase doesnt seem to work. When i have a style for TargetType=Button it works, weird.Maybe the ClickMode is overriden by the default style of every subclass of buttonbase?
Chris
This might might be helpful http://stackoverflow.com/questions/2363774/silverlight-4-and-implicit-styling
dParker
A: 

http://msdn.microsoft.com/en-us/library/system.windows.style%28v=VS.95%29.aspx under Implicit Styles:

In Silverlight 4, you can set styles implicitly. That is, you can apply a certain style to all elements of a certain type. When a resource is declared without an x:Key value, the x:Key value assumes the value of the TargetType property. If you set the style implicitly, the style is applied only to the types that match the TargetType exactly and not to elements derived from the TargetType value. For example, if you create a style implicitly for all the ToggleButton controls in your application, and your application has ToggleButton and CheckBox controls (CheckBox derives from ToggleButton), the style is applied only to the ToggleButton controls.

So there seems to be no way to create a style for ButtonBase and its subclasses.

Chris