私が取り組んでいるアプリケーションには、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 のリソースが見つかりません。
両方のスタイルが同じファイルにある場合はうまく機能します。