0

I need to give users the ability to personalize a Silverlight app by changing the appearance on user-click.

I'm new to Silverlight and am currently going through some tutorials etc. Being familiar with html/css in previous roles I've done some work here on the general styling of existing Silverlight apps. I've now been tasked with adding this personalization and would appreciate some ideas on how I should approach it, many thanks.

Simon Barnett
  • 69
  • 2
  • 9
  • Howdy, you'll inevitably be asked what have you tried? Have you already consulted the search pages for quick results like for example http://weblogs.asp.net/lduveau/archive/2010/05/31/dynamically-apply-and-change-theme-with-the-silverlight-toolkit.aspx – Chris W. Jun 04 '13 at 15:46

1 Answers1

0

You can achieve this by defining your style in Resource dictionary For example You want 2 kinds of appearance for a button lets say theme1 and theme2 So create 2 resource dictionaries such that each resource dictionary contains different style of your button. Then Bind your button style as

<Button Style = {DynamicResource ButtonStyle} Height =23 Width = 70/>

Where ButtonStyle is key of style defined in resource dictionary Now on user click theme1

System.Windows.Application.Current.Resources.MergedDictionaries.Clear();
System.Windows.Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/ProjectName;component/theme1.xaml", UriKind.RelativeOrAbsolute) });

and on user click theme2

 System.Windows.Application.Current.Resources.MergedDictionaries.Clear();
 System.Windows.Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/ProjectName;component/theme2.xaml", UriKind.RelativeOrAbsolute) });

Hope this helps..

Mohd Ahmed
  • 1,422
  • 13
  • 27
  • Thanks, will give it a go and have a play, but not sure if it's going to do everything I want. I want to be able to change the style of many items on a single user-click - to change the appearance of perhaps the whole site. I was thinking along the lines of doing the equivalent of programmatically changing an entire style sheet..? Or something that would achieve a similar result. – Simon Barnett Jun 05 '13 at 08:31
  • yes with above approach you can achieve that. Just define styles for all the controls (that you want to change) in both the resource dictionaries. Changing the resource dictionary at runtime is similar to changing an entire style sheet – Mohd Ahmed Jun 05 '13 at 09:23
  • And change them all individually on the user-click? Also, the approach sounds cool but unfortunately the code didn't actually work for me. I stepped through and the line if hit but it just doesn't do anything. Little more of your precious time...? – Simon Barnett Jun 05 '13 at 09:56
  • you can have a little idea from this link http://silverlightips.wordpress.com/2010/04/29/change-themestyle-using-merged-dictionaries/ – Mohd Ahmed Jun 05 '13 at 10:28
  • That's great thanks - your example above missed reapplying the style after changing the resource file but the one in the link had it and now it works, excellent! – Simon Barnett Jun 06 '13 at 07:57