views:

54

answers:

2

We are embarking on our first Silverlight project, coming from WPF. It's a relatively simple web portal and we would like to avoid references to the Silverlight Toolkit, given our experience with the WPF toolkit.

I'm not much of a coder and have a couple questions related to themes:

  • Implicit styles make this easier. It seems clear you could just switch out resource dictionaries to change your theme. How do I do this without relying on the Toolkit?

  • How do I apply the styles to the entire application, like in WPF, instead of wrapping things in the theme containers? I see there is an ApplicationThemeURI you can use, but that requires the toolkit.

Thanks.

A: 

Applying style to whole app is a simple task in silverlight 4. Put this code in App.xaml or themes/generic.xaml:

<!-- Sample style for each button in the application -->
<Style TargetType="Button">
</Style>

This article could help you: http://www.silverlightshow.net/items/Implicit-Styles-in-Silverlight-4.aspx  

You can change resource dictionary by this way:

var dict = Application.Current.Resources.MergedDictionaries.FirstOrDefault(rd => rd.Source == new Uri("Dictionary1.xaml", UriKind.Relative));
if (dict != null)
     dict.Source = new Uri("Dictionary2.xaml", UriKind.Relative);
vorrtex
Yes this is well understood from our previous experience. I guess the first question was more important--how do we switch the resourcedictionaries when the app is running?
dex3703
Also, you can delete and add resourcedictionary instead of changing source.
vorrtex
Will this update a running silverlight application? I'm tinkering with your sample and some others I've found online but the styles don't change.
dex3703
A: 

Just a note on the Siverlight Toolkit. The last time I used the WPF Toolkit (which was a while ago), I got the impression that it was more-or-less optional. I wouldn't say that the same is true of the Silverlight Toolkit. It adds a great deal of important functionality that would be difficult to implement on your own, and while it's not bug-free, it's pretty reliable. I can't vouch for every aspect of it, but we're using it extensively in a large Silverlight project (~30K lines of code), and we find it indispensable. Unless you're aware of specific issues that your project would encounter, I would recommend that you rethink your decision not to use it.

Ken Smith
That part isn't up to me, which is ultimately good. We aren't crippled by not having it and some team members find any kind of dependency anathema. The site is so simple I don't really get why we're using silverlight at all.
dex3703