【问题标题】:UWP The attachable property 'Resources' was not found in type 'Style'UWP 在“样式”类型中找不到可附加属性“资源”
【发布时间】:2018-04-04 16:29:05
【问题描述】:

ResourceDictionary 文件中,我有一个样式,我尝试向该样式添加一些资源。不幸的是,成员 Resources 无法识别或无法访问。我需要明确地将资源保留在样式中。

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TestProject.Resources">

    <Style>
        <Style.Resources> <!--Style doesn't like it here-->

Uwp 的风格好像不太喜欢。是否有任何等效或足够的解决方法?或者我做错了什么。

【问题讨论】:

    标签: xaml uwp uwp-xaml


    【解决方案1】:

    Style 没有Resources 属性(请参阅documentation)。控件和视觉元素可以。如果要添加资源,可以在控件下添加它们,都与Style 元素处于同一级别:

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:TestProject.Resources">
    
        <SolidColorBrush x:Key="MyBrush" ... />
        <Style>
            <!-- use MyBrush in this style -->
    

    如果您在与Style 相同的级别上定义资源,很遗憾它们将在全球范围内可用,但这与默认 XAML 资源字典 (generic.xaml) 中默认 UWP 样式的定义方式类似。

    【讨论】:

    • 我就是这么想的。在这种情况下,我将对它们中的一些进行硬编码或移动到不同的字典资源或使键更具体并将它们放在全局级别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    相关资源
    最近更新 更多