1

我刚开始使用MetroWindow在 MahApps.Metro 包中找到的,我注意到TreeView在我的 XAML 中不再有边框。我尝试了以下方法,但似乎没有任何影响:

<TreeView x:Name="AssetsTreeView" 
    ItemsSource="{Binding Assets}"
    Height="250"
    BorderThickness="2"
    BorderBrush="Black">
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Items}">
            <TextBlock Text="{Binding Name}" />
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

在我App.xaml的引用中,我引用了以下 4 个样式页面:

<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />

我猜罪魁祸首是其中一种风格,但我想我可以通过元素本身覆盖它(BorderBrush似乎并非如此)。有什么我缺少的东西吗?或者这必须是一种不同的方式吗?BorderThicknessTreeView

4

2 回答 2

2

除非您可以访问,ControlTemplate否则听起来您将无法Border在 that 上设置正常属性TreeView。您可能只需要满足于创建自己的(来自MSDN 上TreeView Styles and Templates页面TreeView ControlTemplate中的默认设置):

<Border Name="Border" CornerRadius="1" BorderThickness="1">
    <Border.BorderBrush>
        <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
    </Border.BorderBrush>
    <Border.Background>
        <SolidColorBrush Color="{DynamicResource ControlLightColor}" />
    </Border.Background>
    <TreeView ... />
</Border>

至少通过这种方式,您将能够根据您的要求进行定制。

于 2013-12-13T09:36:19.853 回答
0

如果Treeview的模板中没有Border with a TemplateBinding on BorderThickness 由样式定义,我认为Controls.xaml,在你的treeview的声明中设置它确实没有效果。

<Style x:Key="{x:Type TreeView}" TargetType="TreeView">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="TreeView">
        <Border Name="Border"
BorderThickness="{TemplateBinding BorderThickness}" <- these may be lacking in the 
BorderBrush="{TemplateBinding BorderBrush}">        <- template defined in the 
                                                       overriding style.
  [...]
于 2013-12-13T08:29:46.523 回答