一种方法是MergedDictionaries
像这样使用:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/assemblyName;component/yourStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--If you want to include additional resources you need to place them here-->
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
</ResourceDictionary>
</UserControl.Resources>
然后在您的 Grid 中,您可以像这样使用它:
<Grid>
<Grid.Resources><!-- This will only use the style in the Grid-->
<Style TargetType="Label" BasedOn="{StaticResource MyStyle}"/>
</Grid.Resources>
</Grid>
这现在应该仅将您的 Style 用于 Grid 或Label
where Style="{StaticResource myStyle}"
。