Ask a questionAsk a question
 

QuestionMerging dictionaries through single xaml file

  • Tuesday, November 03, 2009 5:14 PMDashNYC Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi there,

    I have two resource dictionaries Dict1.xaml and Dict2.xaml. The first one defines a brush, and the second one defines a style that refers to that brush.
    If I merge both Dict1.xaml and Dict2.xaml inside app.xaml, my app works.

    However, if I create another file, e.g. MySkin.xaml and merge both dictionaries in there, and then add MySkin.xaml as the only merged dictionary into app.xaml, I get a runtime error saying the style in Dict2.xaml can't find the brush resource defined in Dict1.xaml.

    Do I need to add some kind of link inside Dict2 to be able to find Dict1's resources?

    The reason I want to merge the dictionaries in a separate file is because I'll have multiple skins for the application, and I'd love to keep parts of each skin in separate files rather than merging them into one big skin file.

    Thanks,
    -Dash.

All Replies

  • Wednesday, November 04, 2009 8:49 AMGeert van Horrik Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    This blog post about a style helper class contains an example how you can devide information into several dictionaries (sizes, brushes, and styles). I hope it will give you some insight on how to merge dictionaries.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
  • Wednesday, November 04, 2009 8:52 AMBruce.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi DashNYC,

    I think it is caused by the Resource look up behavior. Try to use DynamicResource instead of StaticResource to work around the problem.

    This problem has been raised on this forum for many times, if you do a simple search, you will find many hits.

    Best regards,
    Bruce Zhou
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.