简体   繁体   English

Windows Phone 8.1 XAML-覆盖ResourceDictionary条目

[英]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. 我正在使用一个库( https://qkit.codeplex.com/ )在我的应用程序上实现JumpList,并且希望覆盖组标题元素的默认边距。 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: 我已经尝试在应用程序库的JumpList元素正下方的资源字典中设置它,但是它不起作用:

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

Short answer — you can't. 简短答案-您不能。

The authors of the control decided the values aren't part of their public API. 控件的作者决定这些值不是其公共API的一部分。 If they wanted to, they could expose a DependencyProperty on their control that you can change from the outside. 如果他们愿意,可以在控件上公开DependencyProperty,您可以从外部进行更改。

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. 最简单的解决方法-克隆组件的源代码,将QKit项目添加到您的解决方案中,然后根据需要更改QKit \\ Themes \\ generic.xaml。

If you don't want to do that, you can copy generic.xaml into eg 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. 如果您不想这样做,则可以将generic.xaml复制到项目中的例如qkit.xaml中,然后根据需要更改JumpListHeaderItemMargin值,然后将qkit.xaml合并到app.xaml或页面上的资源中您使用该控件。 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. 这样就不会使用DLL中的generic.xaml,因为控件的本地定义样式将覆盖DLL的generic.xaml中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM