WPF change theme/style at runtime

Hi,

Here is an example of how to change in a WPF application the theme at runtime.

WPF change Theme

As you can see  when we cahnge the selected combobox item it automatically changes the theme, which actually clears the application’s resources and loads adifferent xaml file with resources and added this to the SelectionChanged event.

 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ResourceDictionary skin = new ResourceDictionary();
skin.Source = new Uri(@”" + cbxThemes.SelectedValue.ToString() + “.xaml”, UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(skin);
}

Here you can download the sample files.

WPF change Theme sample

12 Responses

  1. DRWebMonkey Says:

    Very cool and simple. I was thinking of using something like to this to allow increased font size as well as the appearance.

    I had to remove the Height Setters to make that work correctly or the button clips the text.

    I would probably have created a directory for the themes, and then read the directory to build the theme list.

    Thanks!

  2. Bill Says:

    Hey good stuff…keep up the good work! :)

  3. Kylie Batt Says:

    Эта блестящая мысль придется как раз кстати…

     private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs […….

  4. Kylie Batt Says:

    Я считаю, что Вы ошибаетесь. Давайте обсудим это….

    Hi,
    Here is an example of how to change in a WPF application the theme at runtime…..

  5. Kylie Batt Says:

    Вы не правы. Я уверен. Могу это доказать. Пишите мне в PM, пообщаемся….

    Hi,
    Here is an example of how to change in a WPF application the theme at runtime…..

  6. MARIO Says:

    < blockquote >< a href=”http://medicamentspot.com/”>Medicamentspot.com. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. No prescription pills. Buy drugs online< /a >…

    Buy:Arimidex.Zovirax.Actos.Lumigan.Mega Hoodia.Valtrex.Retin-A.Prednisolone.100% Pure Okinawan Coral Calcium.Petcam (Metacam) Oral Suspension.Zyban.Prevacid.Synthroid.Accutane.Human Growth Hormone.Nexium….

  7. Lights Says:

    Light http://bclipvsecy9.04FORDPARTS.US/tag/Snap-On+Timing+Light+Lights+Candle/ : Lights…

    Light…

  8. picture Says:

    picture http://wpall9-o.AUTOTECHGUIDE.INFO/tag/picture+mls+running+machine+light+jz/ : running…

    picture…

  9. Crafts Says:

    St http://wsantag0niyjl.01DODGEPARTS.US/tag/Activities+Crafts+St/ : St…

    Activities…

  10. 25 Says:

    inch http://w24dbue7b.04FORDPARTS.US/tag/25+inch+vanities+24+Sink/ : 25…

    inch…

  11. LUTHER Says:

    < blockquote >< a href=”http://cheaptabletsonline.com/”>CheapTabletsOnline.Com. Canadian Health&Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. Online Pharmacy. Order pills online< /a >…

    Buy:Levitra.Maxaman.Viagra Super Active+.Cialis Professional.Viagra Soft Tabs.Soma.Viagra.VPXL.Propecia.Cialis.Viagra Super Force.Tramadol.Viagra Professional.Cialis Super Active+.Super Active ED Pack.Zithromax.Cialis Soft Tabs….

  12. ZACHARY Says:

    < blockquote >< a href=”http://cheaptabletsonline.com/”>CheapTabletsOnline.Com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. High quality pills. Order pills online< /a >…

    Buy:Wellbutrin SR.Lipothin.Cozaar.Female Pink Viagra.Amoxicillin.Female Cialis.Buspar.Seroquel.Lasix.Aricept.Zocor.Nymphomax.Acomplia.Lipitor.SleepWell.Advair.Prozac.Benicar.Zetia.Ventolin….

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.