尝试以编程方式更改Application.Current.Resources中的值时出错

时间:2018-04-08 17:26:39

标签: c# xaml uwp uwp-xaml

当我尝试更改 Application.Current.Resources

中的任何值时出现以下错误
  

System.Runtime.InteropServices.COMException:'未检测到已安装的组件。

     

源设置[Line:0 Position:0]'*

的资源字典中不允许使用本地值

我试图更改系统定义的值以及自定义的值,但是我得到了同样的错误。

Application.Current.Resources["ListViewItemBackgroundSelected"] = new SolidColorBrush(Colors.Black);

Application.Current.Resources.MergedDictionaries.FirstOrDefault()["AccentColor"] = new SolidColorBrush(Colors.Black);

在网络上的多个文档中我看到上面两个是设置资源值的有效方法,因为某种原因它们不适用于我。

BasicPageResources.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:iDownloadManager.UIResources"
    xmlns:UI="using:iDownloadManager.UIpages">

    <SolidColorBrush x:Key="AccentColor" Color="Red"/>
</ResourceDictionary>

的App.xaml

<Application
    x:Class="iDownloadManager.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:iDownloadManager">

    <Application.Resources>
        <ResourceDictionary >
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="UIResources\BasicPageResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

</Application>

0 个答案:

没有答案