Static resource defined in ThemeDictionaries not fetched while edit a copy of the template for custom control

爱⌒轻易说出口 提交于 2019-12-25 00:23:00

问题


Static resource defined in ThemeDictionaries not fetched while edit a copy of the template for custom control.

Is this is behavior or issue?

In my scenario i want to fetch StaticResource from ThemeDictionaries.

Any workaround is there to achive my requirement?

Note: I have used ThemeDictionaries to change the color of my control based on Highcontrast, light and default themes

sample

Regards, Priyanga B


回答1:


One way to solve this issue is to put the 'ThemeDictionaries' in your main project's App.xaml directly. For example:

<Application
x:Class="CustomControlUWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CustomControlUWP"
xmlns:Input="using:CustomControl1"
RequestedTheme="Light">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Light">
                <SolidColorBrush x:Key="Backcolor" Color="Black"/>
            </ResourceDictionary>
            <ResourceDictionary x:Key="Default">
                <SolidColorBrush x:Key="Backcolor" Color="Pink"/>
            </ResourceDictionary>
            <ResourceDictionary x:Key="HighContrast">
                <SolidColorBrush x:Key="Backcolor" Color="Red"/>
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Application.Resources>

Another way is to define the ThemeDictionaries in separate xaml files in your class library, and in your main project's App.xaml, you could add reference to the resource dictionary like this thread: Linking ThemeDictionaries in Library Project



来源:https://stackoverflow.com/questions/48562478/static-resource-defined-in-themedictionaries-not-fetched-while-edit-a-copy-of-th

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!