问题
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