Question

I just started using the MetroWindow found within the MahApps.Metro package and I noticed that the TreeView in my XAML no longer has a border. I've tried the following but it didn't seem to have any affect:

<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>

In my App.xaml I have the following 4 style pages referenced:

<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" />

I'm guessing the culprit is in one of the styles but I figured I could overwrite it via BorderBrush and BorderThickness on the TreeView element itself (which doesn't seem to be the case). Is there something I'm missing to do this or does this have to be a different way?

Was it helpful?

Solution

Unless you can get access to the ControlTemplate then it sounds like you won't be able to set the normal Border properties on that TreeView. You might just have to settle for creating your own (from the default TreeView ControlTemplate found in the TreeView Styles and Templates page on MSDN):

<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>

At least this way, you'll be able to customise to your requirements.

OTHER TIPS

If there is no Border with a TemplateBinding on BorderThickness in the Treeview's template defined by the style in, I think Controls.xaml, setting it in the declaration of your treeview will indeed have no effect.

<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.
  [...]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top