Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Theming and Skinning in SL2B2
12 replies. Latest Post by Simbalight on July 23, 2008.
(0)
Simbalight
Member
245 points
87 Posts
07-04-2008 8:34 AM |
Hi!
Is there any theme mechanism built into SL2 B2? I know that in B1 there was none.
How would you do the job of dynamically changing the theme?
'Mutliple xaps' sounds like a solution but I cannot create separate xaps for every possible language / theme combination.
I would neither want to parse all the controls and set their skins one by one because I don't know which button would use skin1 from theme1 and which skin2 from theme1. If there's nothing built in or planned for RTM, something like "dynamic generic.xaml loading" sounds like an option...
Any experiences, info, links?
Dave Relyea
Participant
1084 points
249 Posts
07-04-2008 3:08 PM |
I'd be interesting in hearing the details of what you are trying to do. Global "theme switching" is definitely something we're thinking about for the future, but it will not be in SL2.
You could walk the visual tree using VisualTreeHelper, and set the Templates to a new template based on what the old template was.
07-07-2008 3:31 AM |
It's planned to be a multilingual business application. The user should be able to choose the theme for the entire UI. So global theme switching would be exactly what we need. However it would be acceptable if the approach requires the application to reload. I don't want to build a separate xap for each skin because we will already use multiple xaps to provide multilanguage support.
I know how to load files on demand, but is it possible to load a resource file containing the stuff that would normaly reside in generic.xaml? It could happen in the application class.
My investigations so far make me believe I cannot simply move generic.xaml content to another resource xaml file. Is this correct? Is there a way around?
DanielDo...
2 points
2 Posts
07-07-2008 5:18 AM |
I don't mean to hi-jack this thread but the company I work for requires this as well. We have roughly 20 different languages (represented not only by text, but graphical resources as well) for each product and the product is also re-skinned for approx. 20 different customers (some of them needs a red theme of backgrounds, buttons; some need blue).
Until Silverlight supports something like this we are stuck with Flash even though we would very much like to make the switch. Any idea on how to achieve this skinning/theming in Silverlight 2 or do we have to wait for 3.0?
slyi
810 points
247 Posts
07-07-2008 6:46 AM |
The AOL mail application had skins, back in Mix08 http://sessions.visitmix.com/?selectedSearch=BT01, which was done by reloading each control with a different styles, would that not work for you.
Also you dont need to create a seperate xap for each language, please see sample on http://silverlight.services.live.com/invoke/6655/LocSample/iframe.html and other articles on loc at http://wpf-e.spaces.live.com/,
Please note downloading a xap for single language resources on demand may be useful if you have a very large number of strings and languages, i'll blog about this later.
regards,
07-08-2008 3:33 AM |
Hi,
I suppose it would work but it just doesn't seem elegant and my favorite way to go. Of course if it's the only way by now there's no choice :)
If I assign explicit styles to the controls I could decide which library to load on app startup, each of them containing that styles. I will play around with that idea and do some tests, soon. But most controls I use are custom ones and I'd love to change controls that use their "built-in style" on the fly (or on app startup), too.
Of course I could build several versions of the control library but wouldn't it be nice to have an on demand skin dll? We load it, assign it and we're done?!
Still I'm not sure which way to go. When I'll have news about any approach I will update this thread.
I'm ok with multiple xaps for multiple languages. However I know that thread and your blog and I've been following it for a while now. Maybe I'm going to pack the two most important languages into the main xap and load others on demand. BTW: good work!
Regards
Kevmeister
249 points
119 Posts
07-08-2008 4:00 AM |
Our organisation also requires theming. There are 2 issues which need to be addressed - the default styles of controls as shipped need to be themable, and a means of packaging user-defined styles into collections called "themes".
07-09-2008 7:52 AM |
I tried to check one of the options: Downloading an assembly and using its resources to set a new skin. I know how to download an assembly but how to use its resources for my purposes?
In the Mix08 slides for the AOL Mail app they write "loads skin assembly" and sth about a method "GetControlTemplate". How would that assembly look like and how to use it?
If anyone tried it, please help out!
hwsoderlund
411 points
116 Posts
07-10-2008 3:11 AM |
Take a look at this, it looks like a good solution to the theming problem:
http://www.nikhilk.net/Entry.aspx?id=201
kalyan.
9 points
31 Posts
07-22-2008 10:54 AM |
Hi hwsoderlund,
Thanks alot for the Link.
The one Sample which is there in the Link(http://www.nikhilk.net/Entry.aspx?id=201) is uesd with Static Theme.
I got the requirement in such away to set the Theme Dynamically.
Could you tell me how to set the theme Dynamically(in the .CS File ).
With Regards,
kalyan
07-22-2008 4:33 PM |
Did you see http://leeontech.wordpress.com/2008/07/21/dynamic-styles/
07-23-2008 1:35 AM |
Hi slyi,
Thanks a lot for the Link.It helps me alot.
07-23-2008 4:28 AM |
Lee's approach from Slyi's link is great! No need to traverse the element tree! The only thing I would like to add is being able to use the controls' pre-defined skins and use skin switching as well. Pre-defined skins reside in the generic.xaml files inside the control libraries. I can't find a way to dynamically load a new version of such file in a way that controls would automatically pull their skins from the new file.
So up to now there are two options:
- Copy the pre-defined skins and use style-attributes for all the controls
- Traverse the element tree and set styles for all controls that use pre-defined styles
If anyone has an idea/approach how it could be done without traversion and obligatory style-attributes, please post it here!