Search code examples
c#xamlwindows-phonewindows-phone-8.1

Windows Phone 8.1 XAML - Overriding ResourceDictionary entry


I'm using a library (https://qkit.codeplex.com/) to implement a JumpList on my app and I wish to override its default margin for group header elements. This margin is defined on the library code as a resource in a resource dictionary:

<Thickness x:Key="JumpListHeaderItemMargin">19,0,0,9.5</Thickness>

How do I override the value for this key though? I already tried setting it in a resource dictionary directly under the library's JumpList element on my app, but it didn't work:

<q:AlphaJumpList Name="lineJumpList">
    <q:AlphaJumpList.Resources>
        <Thickness x:Key="JumpListHeaderItemMargin">0,0,0,9.5</Thickness>
    </q:AlphaJumpList.Resources>
    ...
</q:AlphaJumpList>

Solution

  • Short answer — you can’t.

    The authors of the control decided the values aren’t part of their public API. If they wanted to, they could expose a DependencyProperty on their control that you can change from the outside.

    The simplest workaround — clone the source code of the component, add QKit project into your solution, and change QKit\Themes\generic.xaml however you like.

    If you don’t want to do that, you can copy generic.xaml into e.g. qkit.xaml in your project, then change JumpListHeaderItemMargin value however you like, then merge qkit.xaml into either app.xaml or into resources on the page where you use that control. This way generic.xaml from the DLL won’t be used, because locally-defined style for the control will override what’s in the DLL’s generic.xaml.