我正在尝试在我的WPF程序中使用ResourceDictionary和Style。当我只在<Window.Resources>
中使用ResourceDictionary时,一切正常,但是当我添加一个<Style>
时,程序会显示“找不到资源”字样,并且我会收到一个错误:“无法解析资源“PlusMinusExpander”。”
<Window.Resources>
<Style x:Key="CurrencyCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Foreground" Value="#dddddd" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
<ResourceDictionary x:Key="hello" Source="Assets/PlusMinusExpanderStyles.xaml" />
</Window.Resources>
<Expander Header="Plus Minus Expander" Style="{StaticResource PlusMinusExpander}" HorizontalAlignment="Right" Width="292">
<Grid Background="Transparent">
<TextBlock>Item1</TextBlock>
</Grid>
</Expander>
即使添加CurrencyCellStyle样式,我仍希望能够使用Style="{StaticResource PlusMinusExpander}"
。我在网上看到过类似的问题,但它们的解决方案都还没有对我起作用。是否有一种方法可以同时使用样式和ResourceDictionary?