1

I have a UserControl which contains a TreeView and a TextBlock:

<TreeView ItemsSource="{Binding FirstGeneration}" AllowDrop="True"  Drop="TreeView_Drop" Width="300">

                <TreeView.ItemContainerStyle>

                    <Style TargetType="{x:Type TreeViewItem}">

                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
          <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
          <Setter Property="FontWeight" Value="Normal" />

                    <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
              <Setter Property="FontWeight" Value="Normal" />
            </Trigger>
          </Style.Triggers>
        </Style>
      </TreeView.ItemContainerStyle>

      <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal" >
                        <Image Source="{Binding Path=Image}" />
                        <TextBlock Text="{Binding Name}" />
                    </StackPanel>
                </HierarchicalDataTemplate>
      </TreeView.ItemTemplate>
    </TreeView>
     <TextBlock Height="23" Name="textBlock1" Text="{Binding= ???}" Width="187" />

When I select an item of the treeview, I want do show some informations contained in the item (eg : the name of the selected item).

My problem is that I don't know how doing this binding, because when I select an item, the setter IsSelected of the item class is called.

Have you a best practice for doing that ?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Michaël
  • 6,676
  • 3
  • 36
  • 55

1 Answers1

1

Have a look at this in MSDN. And also the BindableSelectedItemBehaviour here.

Community
  • 1
  • 1
anivas
  • 6,437
  • 6
  • 37
  • 45