无法将 ItemsPresenter 与 DynamicResource 包装在一起



我正在使用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"。 ---> System.InvalidCastException:不能在类型"System.Windows.Style"上强制转换类型为"System.Windows.Media.SolidColorBrush"的对象。

为什么会这样?

MaterialDesignPaper 是画笔,而不是样式。

因此,根据您的要求,您需要这样的东西:

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

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

最新更新