locked
Update embedded image resources when theme changes RRS feed

  • Question

  • UPDATE: I figured out my answer and it was very simple.  Rather than having:

    <Image Source="{StaticResource TopCorner}" />

    just needed

    <Image Source="{DynamicResource TopCorner}" />

     

    -----------------------------

    I have several themes that users can switch between at run time.  When they choose a new theme, I update the them and all buttons, labels, etc. styles are updated to the new theme but images are not. 

    When I change a theme, I execute the following:

    app.Resources.MergedDictionaries.Remove(OLDThemeResourceDictionary);

    app.Resources.MergedDictionaries.Add(NEWThemeResourceDictionary);  

    I have several images that are set as:

    <Image Source="{StaticResource TopCorner}" />

    In each of my theme resource files, I have these image sources set as:

    <ImageSource x:Key="TopCorner">/myAssembly;component/Images/XXX_top_corner.png</ImageSource>

    where the 'XXX' portion is different pending the theme.  All images are set as Build Action = Resource. 

    When I change theme, these images are not being updated.  I am looking for a way to make it work somehow, some way.  If I'm going about this wrong, feedback on that would certainly be appreciated as well.

    Thanks for looking!

    • Edited by BGort Wednesday, February 16, 2011 10:20 PM Update - Found Answer
    Wednesday, February 16, 2011 10:12 PM

Answers

  • Hi BGort,

    I’m glad to hear that the problem is resolved.

    As you have discovered, you can use DynamicResource if you intend to change the change the theme. You can see Resources Overivew for more information about WPF Resources.

    Thank you for sharing your experience here. It is very beneficial for other community members having the similar questions.


    Best regards,
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Min Zhu Tuesday, February 22, 2011 2:21 AM
    Thursday, February 17, 2011 3:18 AM