views:

25

answers:

0

I found the following code for showing the selected item in a treeview when focus has left, but I'm having trouble moving the code to App.xaml so any UserControl could use it.

This does what I want

<TreeView x:Name="trviewArchives" Width="141" Height="154" Canvas.Left="20" Canvas.Top="167"  Background="{x:Null}" BorderBrush="#FF081827" BorderThickness="0">
            <TreeView.Resources>
                <TreeViewItem x:Key="bold" FontWeight="Bold" />
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Peru"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Peru"/>
            </TreeView.Resources>

But I can't figure out how to make a style out of it. I've tried the following, which seams syntactically correct

            <Style x:Key="TreeStyle" TargetType="{x:Type TreeView}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TreeViewItem">
                        <TreeViewItem>
                            <Setter x:Name="bold" Property="FontWeight" Value="Bold" />
                        </TreeViewItem>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

And in the usercontrol

<TreeView x:Name="trviewArchives" Width="141" Height="154" Canvas.Left="20" Canvas.Top="167"  Background="{x:Null}"  Style="{DynamicResource ResourceKey=TreeStyle}"
                  BorderBrush="#FF081827" BorderThickness="0" >

At one point the UserControl code recognized the style, but currently its showing "resource TreeStyle could not be resolved".
What am i doing wrong?
Do I need to scope TreeStyle since its in App.xaml which is a different (parent) namespace? Once I get it using the style, what is the syntax for setting the other properties?