tags:

views:

32

answers:

1

Hi,

I have got a Rectangle inside the HierarchicalDataTemplate of a TreeView. On selectedItemChange event of Treeview i have to change the color of the Rectangles coming as children under that selected node. I am not able to assign a name to the rectangle during binding. It is showing an error 'Text representation expected for name property'. If i can give a name to the rectangle while binding i think it is possible to change its color.Is there any way to tackle this situation.

<controls:TreeView x:Name="tree" ItemsSource="{Binding Path=Source, Source={StaticResource SourceClass}}" Margin="0,0,8,0" Background="#FFF8D1D1" Grid.RowSpan="4"  SelectedItemChanged="tree_SelectedItemChanged" >
        <controls:TreeView.ItemTemplate>
            <data:HierarchicalDataTemplate ItemsSource="{Binding Children}">                    
                <StackPanel>
                    <Rectangle Width="20" Height="20" Stroke="Black" Fill="Red" ToolTipService.ToolTip="{Binding Name}"  DataContext="{Binding Name}" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown">
                    </Rectangle>
                    <TextBlock Text="{Binding Name}" ></TextBlock>

                </StackPanel>

            </data:HierarchicalDataTemplate>
        </controls:TreeView.ItemTemplate>
    </controls:TreeView>
A: 

Are you changing the color based on one of the properties of the Item? If so, you could bind the color to that property and write a value converter if necessary to determine the color.

Mike