无法使用 DynamicResource 包装 ItemsPresenter
Cannot wrap ItemsPresenter with a 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: Unable to cast objects of type 'System.Windows.Media.SolidColorBrush' to type 'System.Windows.Style'. ---> System.InvalidCastException: Can not cast objects of type 'System.Windows.Media.SolidColorBrush' on the type 'System.Windows.Style'.
为什么会这样?
MaterialDesignPaper 是画笔,不是样式。
因此,根据您的要求,您需要这样的东西:
<Border BorderBrush="{DynamicResource MaterialDesignPaper}" />
要么
<Border Background="{DynamicResource MaterialDesignPaper}" />
所有 Material Design In XAML 笔刷列于此处:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Brush-Names
我正在使用 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: Unable to cast objects of type 'System.Windows.Media.SolidColorBrush' to type 'System.Windows.Style'. ---> System.InvalidCastException: Can not cast objects of type 'System.Windows.Media.SolidColorBrush' on the type 'System.Windows.Style'.
为什么会这样?
MaterialDesignPaper 是画笔,不是样式。
因此,根据您的要求,您需要这样的东西:
<Border BorderBrush="{DynamicResource MaterialDesignPaper}" />
要么
<Border Background="{DynamicResource MaterialDesignPaper}" />
所有 Material Design In XAML 笔刷列于此处:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Brush-Names