我正在使用MaterialDesignInXaml对我的应用程序进行样式化。说到这一点,我使用了一个ListView和一个CollectionViewGroup来分组我的项目,不管怎么说,在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’类型的对象。
为什么会发生这种事?
发布于 2018-01-30 09:40:26
MaterialDesignPaper是一种刷,而不是一种风格。
因此,根据您的需求,您需要这样的内容:
<Border BorderBrush="{DynamicResource MaterialDesignPaper}" />或<Border Background="{DynamicResource MaterialDesignPaper}" />
XAML笔刷的所有材料设计都列在这里:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Brush-Names
https://stackoverflow.com/questions/48490855
复制相似问题