Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is IsSynchronizedWithCurrentItem property (or equivalent) for a TreeView?

Tell me it ain't so.

I have a typical windows/file explorer like setup.

  • Left Side I have a TreeView all data bound showing nodes in a hierachy
  • Right Side I have a ListView showing Node.Properties

ListView has a IsSynchronizedWithCurrentItem property, which rocks. e.g. If I had another ListView showing a list of nodes and both listViews have this property set to true. Changing selection of node in NodesListView will update the PropertiesListView automatically.

Now I need the same thing with a NodesTreeView and a PropertiesListView... and seems like TreeView has no such property.

Is there a more 'the WPF way' kind of solution to this problem ? Or do I have to handle the NodeSelectionChanged event of the Tree and refresh the listView via code.

like image 272
Gishu Avatar asked Dec 17 '08 09:12

Gishu


1 Answers

A really simple solution is to bind your "details" UI elements to the SelectedValue property of the TreeView. For example, if your TreeView looked like this:

<TreeView Name="CategoryName" ItemsSource="{Binding Source={StaticResource A_Collection}, Path=RootItems}" />

Then you could bind details UI elements (like a textbox) using:

<TextBox Text="{Binding ElementName=CategoryTreeView, Path=SelectedValue.Name}"/>

Would cause the text box to be bound to Name property of the items currently selected in the TreeView.

If you want to bind many UI items as details for the selected TreeView item, consider setting up a DataContext on the elemtent that contains all the details controls (DockPanel / Grid / StackPanel, etc).

like image 65
Mark Avatar answered Sep 19 '22 00:09

Mark