WPF Custom Control Resources Best Practices RRS feed

  • Question

  • Hi everyone,

    I'm currently developing a custom control and I've run into some issues with resources in general.

    1. Where should I put resources like Paths or DrawingImages?

    2. Should a <Path> be always wrapped in a ViewBox when stored in a resource dictionary?

    3. If I already have some resourcedictionaries in the control's assembly should I merge them with the application resources?

    4. How can I prepare a custom control for implicit styling? I mean the control should be able to get styles from the application level ...

    5. Any other best practices regarding custom control and resources highly welcome :)

    Tuesday, October 16, 2012 1:09 PM


  • If your AssemblyInfo.cs is set as

    [assembly: ThemeInfo(
        ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
        //(used if a resource is not found in the page,
        // or application resource dictionaries)
        ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
        //(used if a resource is not found in the page,
        // app, or any theme specific resource dictionaries)

    You could store these resources in the general.xaml file, since it will be merged into the App resource dictionary at run-time implictly. Or you could also create separate resource dictionary files to store them, and write the merged code in your app.xaml.

    For more about the ThemeInfo, please view http://msdn.microsoft.com/en-us/library/system.windows.themeinfoattribute.aspx

    Have a nice day,

    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Kee Poppy Tuesday, October 30, 2012 8:23 AM
    Friday, October 19, 2012 9:21 AM