1

私はカスタムColor.xamlを持っています

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <SolidColorBrush x:Key="MyColor1" Color="#7d897d"/>
    <SolidColorBrush x:Key="MyColor2" Color="#078ab4"/>
</ResourceDictionary>

そしてApp.xamlは

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!-- Defines the colors used in the app-->
                <ResourceDictionary Source="Color.xaml"/>
                <!-- Styles that define common aspects of the platform look and
                     feel Required by Visual Studio project and item templates-->
                <ResourceDictionary Source="StandardStyles.xaml"/>
                <ResourceDictionary>
                ............

My StandardStyle.xamlで、xamlで定義された色を使用できません。

<Style x:Key="HeadingTextStyle" TargetType="TextBlock">
    <Setter Property="FontWeight" Value="SemiLight"/>
    <Setter Property="FontSize" Value="20"/>
    <Setter Property="Foreground" Value="{StaticResource MyColor1}"/>
</Style>

コードを実行すると例外が発生します

"Cannot find a Resource with the Name/Key MyColor1 [Line: 20 Position: 44]"

ただし、UIxamlファイルでこの色を使用することはできます。

4

1 に答える 1

1

ここにありColor.xamlますStandardStyle.xaml

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

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Color.xaml"/>    
    </ResourceDictionary.MergedDictionaries>

    <!-- your styles here -->

</ResourceDictionary>
于 2012-11-07T06:20:01.117 に答える