views:

1000

answers:

3

Is there a way to automatically apply a theme/template/style to all controls of the targettype, so I don't have to specify Template=..., Style=... on all controls?

+2  A: 

I thought there was a way to do this by just omitting the x:Key attribute, but that doesn't seem to work anymore. Based on some googling it seems to me like you're best best is to create a custom control library of your own that has a themes/generic.xaml file that defines your custom styles. Then you can use your own elements that are styled properly (MyButton instead of Button). Either that or stick with the Style property.

Some example of this here and an alternate approach using themes here.

Update: Just found a really good example of this here (I think you might have already seen it :).

Bryant
A: 

Thanks for your answer.

I was also considering creating a manager that could apply the style dynamically by getting the resource and applying automatically all the controls based upon targettype found in the resource.

EinarI
A: 

Einarl: Right now there isn't a way to "cascade" control templates/styles in Silverlight 2 core. That is to say that you can't set a style/control template for TextBox and expect all TextBoxes to pick it up. It is definitely something the team is looking into for future versions.

Tim Heuer