locked
How can i define my own Theme Resource Keys inside my class library and override them on the App?

    Question

  • I would like to define custom ThemeResource keys inside my class library and use it in UserControls also defined inside my

    class library.

    I then have a need for my Application to override those values.

    Heres a concrete example. I need to define an AppColor ThemeResource key inside my class library. UserControls inside the class library should be able to reference and use it.

    Now each individual Application that uses my library should be able to redefine this key and specificy it's own specific Application color.

    How do i structure this?

    Friday, December 19, 2014 10:54 PM

All replies

  • Hi Anargyros,

    let's say if we have a ResouceDictionary named Dictionary1.xaml in our Class Library, first step is to set it as "Content"

    Then in our main project, we can ref the resousce like below:

                Resources.Source = new Uri("ms-appx:///ClassLibrary1/Dictionary1.xaml", UriKind.RelativeOrAbsolute);
                var t = this.Resources["fadeBrush"];

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 22, 2014 7:11 AM
    Moderator
  • Anyway, I'm thinking what kind of scenario you are having to implement a ThemeResource in Class Library, if you need to modify some color inside UserControl, you can directly re-write the Color property.

    I think if you could tell us your scenario that could be easier for us to provide you more sufficient suggestions and benefit your development.

    --james


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 25, 2014 8:36 AM
    Moderator
  • I think my original description of my requirements is pretty spot on.
    Monday, January 5, 2015 5:55 PM
  • Hi Anargyros,

    How about my code, does this fulfill your requirements?

    Why I want to ask your scenario because the way you are working looks like hardcode and I would like to know your scenario so that can provide you a better and easier way to implement this for example do not hared code the color and re-write it each time. :)

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, January 6, 2015 7:30 AM
    Moderator
  • Hi James,

    I would like to define a ThemeResource and not just any static resource.
    The reason for this is that i want the value to change based on the current theme (Light, Dark, HighContrast). This is very much inline with how Microsoft has architected Themes.
    I only need to figure out how to specify my own keys along side the huge MS ThemeResources.xaml file.

    My Color resource needs to be dependant on the current theme. My Color resource needs to be accessible from inside the class library that defines it (similar to how MS libraries are able to reference the Theme resources) but also my apps need to be able to override those values on the app level (again identically with how an app developer can do now with MS resources i.e you can respecify them in App.xaml under the ThemeDictionaries and essentially override the ones they need tweaked).

    Hope this clarifies it a little better.


    Tuesday, January 6, 2015 8:18 AM