C# WPF。使用其他字典中的资源设置BasedOn属性

C# WPF。使用其他字典中的资源设置BasedOn属性,c#,wpf,xaml,C#,Wpf,Xaml,我对WPF比较陌生。我有两个带有样式定义的字典,稍后在XAML视图中使用 CommonStyles.xaml中的基本样式: 我想做的是使用CommonStyles.xaml中定义的样式RoundCornerButton作为RoundCornerButton的父样式,并检入SpecificStyles.xaml,我的意思是,作为BasedOn属性类型继承的值 我也尝试过以这种方式设置属性based: BasedOn={StaticResource{local:Style RoundCornerBu

我对WPF比较陌生。我有两个带有样式定义的字典,稍后在XAML视图中使用

CommonStyles.xaml中的基本样式:

我想做的是使用CommonStyles.xaml中定义的样式RoundCornerButton作为RoundCornerButton的父样式,并检入SpecificStyles.xaml,我的意思是,作为BasedOn属性类型继承的值

我也尝试过以这种方式设置属性based: BasedOn={StaticResource{local:Style RoundCornerButton}

由于CommonStyles.xaml位于文件夹Theme/insidemyproject/中,因此我认为可以通过local:namespace以某种方式访问它, 但我不知道该怎么做


我也在查看属性的文档,但我仍然感到困惑。

如果您希望能够使用StaticResource标记扩展引用SpecificStyles.xaml中CommonStyles.xaml中定义的资源,您应该将前一个ResourceDictionary合并到后一个中:

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

    <Style x:Key="RoundCornerButtonWithCheck" TargetType="{x:Type Button}" BasedOn="{StaticResource RoundCornerButton}">
        ...
    </Style>


</ResourceDictionary>
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyProject.Theme">
    <...>
    <Style x:Key="RoundCornerButtonWithCheck" TargetType="{x:Type Button}" BasedOn="{StaticResource RoundCornerButton}">
        <...>
    </style>
</ResourceDictionary>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="CommonStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="RoundCornerButtonWithCheck" TargetType="{x:Type Button}" BasedOn="{StaticResource RoundCornerButton}">
        ...
    </Style>


</ResourceDictionary>