无法使用DynamicResource包装ItemsPresenter

时间:2018-01-28 20:17:06

标签: wpf xaml material-design-in-xaml

我正在使用MaterialDesignInXaml来设置我的应用程序样式。说,我正在使用带有CollectionViewGroup的ListView对我的项目进行分组,无论如何,在GroupStyle我有这样的结构:

<GroupStyle>
<GroupStyle.ContainerStyle>
    <Style TargetType="{x:Type GroupItem}" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Expander IsExpanded="True">
                        <Expander.Header>
                            <DockPanel Height="16.5">
                                <TextBlock Text="{Binding Name.Name}" FontWeight="Bold" Foreground="White" FontSize="11.5" VerticalAlignment="Bottom" />
                                <TextBlock Text="{Binding ItemCount}" FontSize="11.5" Foreground="Orange" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
                            </DockPanel>
                        </Expander.Header>
                        <Border Style="{DynamicResource MaterialDesignPaper}">
                            <ItemsPresenter />
                        </Border>
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</GroupStyle.ContainerStyle>
</GroupStyle>

现在问题出在这一行:<Border Style="{DynamicResource MaterialDesignPaper}">,如果我删除边框一切正常,但是上面的xml我得到了这个例外:

  

System.Windows.Markup.XamlParseException:无法将类型为“System.Windows.Media.SolidColorBrush”的对象强制转换为“System.Windows.Style”。 ---&GT; System.InvalidCastException:无法在类型'System.Windows.Style'上强制转换'System.Windows.Media.SolidColorBrush'类型的对象。

为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

MaterialDesignPaper是一个Brush,而不是Style。

因此,根据您的要求,您需要以下内容:

<Border BorderBrush="{DynamicResource MaterialDesignPaper}" /> 要么 <Border Background="{DynamicResource MaterialDesignPaper}" />

此处列出了XAML画笔中的所有材质设计:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Brush-Names

相关问题