6

私が取り組んでいるアプリケーションには、2 つの ResourceDictionary、DefaultStyles.xaml、および CustomStyles.xaml があります。

CustomStyles ディクショナリのスタイルが、他のディクショナリで定義された基本スタイルを使用する可能性はありますか?

DefaultStyles.xaml:

<Style x:Key="TextBlockDefaultStyle" TargetType="TextBlock">  
    <Setter Property="Margin" Value="4" />  
</Style>  

CustomStyles.xaml:

<Style x:Key="SectionTitleStyle" TargetType="TextBlock" BasedOn="{StaticResource TextBlockDefaultStyle}">
    <Setter Property="FontSize" Value="16" />
</Style>

アプリ.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Assets/Styles/DefaultStyles.xaml"/>
            <ResourceDictionary Source="Assets/Styles/CustomStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

コードを実行すると、次の例外がスローされます。

名前/キー TextBlockDefaultStyle のリソースが見つかりません。

両方のスタイルが同じファイルにある場合はうまく機能します。

4

1 に答える 1

8

他のスタイルの辞書を直接参照する必要があります。

CustomStyles.xaml:

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

<Style x:Key="SectionTitleStyle" TargetType="TextBlock" BasedOn="{StaticResource TextBlockDefaultStyle}">
    <Setter Property="FontSize" Value="16" />
</Style>
于 2011-01-10T17:39:09.910 に答える