开发者

How do I handle changing of themes?

I have a Silverlight 4.0 application and it's corresponding Styles.xaml for each of the theme. I know what code to write to change the ResourceDictionary and all. Basically I need a conceptual idea from you. I have a query string in my URL like ?uid=3. The themes are users based. So A can have a theme different than B.

As far as I know, if you have implicit styles defined, you can write the code to change the theme anywhere in your application 开发者_运维知识库and it will work out just fine. However, if your resource dictionary defines explicit styles then you have to compulsorily set the theme in App.xaml.cs constructor. Let me know if I am wrong! Now the problem with this is the user may browse A's profile and then may shift to B's. If this happens the theme won't be changed because App.xaml.cs's constructor runs only once when your application starts. How do I handle this? One option is to never create explicit styles and keep all of them implicit. Do you guys have any other option?

Second question is as the theme keeps changing as user browses the page, do I need to keep making a webservice call to retrieve what theme applies to this specific user? This will make a huge performance hit as you make an extra webservice call in every page. Is this acceptable or do you have any other better option?

P.S: One other solution is I create a base page and in that page store a _previousUserId. If the currentUserId (fetched from query string) doesn't match the _previousUserId, I make a call to see which theme this specific user has set for his profile and after webservice call, make _previousUserId = currentUserId (so next time call won't be made as long as the user is on this userId's profile).

But yet another problem with solution is: the page will load all it's data with old theme as long as the response from the webservice to get the new theme doesn't come. This looks buggy. Eg. The user first visits A's profile so his theme will be fetched from webservice and applied. Then he visits B's profile but the theme will be still A's until the asynchronous call to get B's theme returns.

How do you handle all of these things?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜