xyzzer / WinRTXamlToolkit

WinRT XAML Toolkit
Other
282 stars 67 forks source link

How do I bind TreeView selected item to ViewModel? #34

Closed nehmebilal closed 8 years ago

nehmebilal commented 8 years ago

Can't find any docs and the video link is not working.

xyzzer commented 8 years ago

Sorry, I think they removed the video. I don't think it had the details you're looking for anyway. The sample doesn't show what you're asking about indeed, but you should be able to bind the SelectedItem property of the TreeView to your view model. If you want to bind the selection state of each tree node to the node model - the visual tree debugger shows how it can be done. using the IsSelectedBindingPath property.

https://github.com/xyzzer/WinRTXamlToolkit/blob/master/WinRTXamlToolkit.Debugging/Views/VisualTreeView.xaml

    <controls:TreeView
        x:Name="treeView"
        ItemsSource="{Binding RootElements}"
        ItemTemplate="{StaticResource TreeViewItemTemplate}"
        IsSelectedBindingPath="IsSelected"
nehmebilal commented 8 years ago

Awesome thanks!