开发者

UserControl databinding with a treeview

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 ?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜