Search code examples
silverlightxamlpersonalization

Silverlight App - Change Styles on User-Click


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.


Solution

  • 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..