小编shr*_*eya的帖子

在 WPF 中将 ResourceDictionary 与其他样式一起使用

我正在尝试在我的 WPF 程序中使用 ResourceDictionary 和 Style。当我只有 ResourceDictionary 时,<Window.Resources>一切工作正常,但一旦我添加一个<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>
Run Code Online (Sandbox Code Playgroud)

Style="{StaticResource PlusMinusExpander}"我希望即使在添加CurrencyCellStyle 样式之后也能做到这一点。我在网上看到过类似的问题,但他们的解决方案还没有对我有用。有没有办法同时使用样式和资源字典?

c# wpf xaml resourcedictionary

3
推荐指数
1
解决办法
1562
查看次数

标签 统计

c# ×1

resourcedictionary ×1

wpf ×1

xaml ×1