【发布时间】:2021-07-31 13:09:34
【问题描述】:
我正在为我的应用添加复杂的主题。我的想法是当用户更改主题时,我会加载一个 ResourceDictionary 并在运行时更改它的子项。 但是插入操作总是失败,请帮帮我。
以下是我所做的:
auto newResourceDic = ref new ResourceDictionary();
newResourceDic->Source = ref new Uri("ms-appx:///XAMLPages/test.xaml");
if (newResourceDic->HasKey(L"TitleBarColor"))
{
newResourceDic->Remove(L"TitleBarColor");
//It's a SolidColorBrush, I want to replace this brush to a more complex bitmapbrush
//For convenience, I use a solidcolorbrush instead
Windows::UI::Color c;
c.A = 255;
c.R = 255;
c.G = 0;
c.B = 0;
testbrush = ref new Windows::UI::Xaml::Media::SolidColorBrush(c);
//HRESULT:0x800F1000 No installed components were detected.
//WinRT information: Local values are not allowed in resource dictionary with Source set [Line: 0 Position: 0]
newResourceDic->Insert("TitleBarColor", testbrush);
}
【问题讨论】: