I have a TreeView and ListBox on the view. How can I change the data in the ListBox depending on what is selected in the TreeView? I found the SelectedItemChanged event at TreeView but I don’t understand how to use it with snapping. In fact, I just need a function call in which I will write something like
RegValues = SelectedKey.GetContent(); slice view.xaml
<TreeView Name="tree" ItemsSource="{Binding TreeViewData}" SelectedValuePath="{Binding SelectedKey}" > <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=ChildGroup}"> <TextBlock Text="{Binding name}"/> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView> a piece of viewmodel.cs
public List<String> RegValues { get { int i = 0; return (List<String>)GetValue(RegValuesProperty); } set { SetValue(RegValuesProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty RegValuesProperty = DependencyProperty.Register("RegValues", typeof(List<String>), typeof(Level2PageViewModel)); public RegModel SelectedKey { get { return (RegModel)GetValue(SelectedKeyProperty); } set {SetValue(SelectedKeyProperty, value);} } // Using a DependencyProperty as the backing store for SelectedValue. This enables animation, styling, binding, etc... public static readonly DependencyProperty SelectedKeyProperty = DependencyProperty.Register("SelectedKey", typeof(RegModel), typeof(Level2PageViewModel)); public List<RegModel> TreeViewData { get { return (List<RegModel>)GetValue(TreeViewDataProperty); } set { SetValue(TreeViewDataProperty, value); } } // Using a DependencyProperty as the backing store for TreeViewData. This enables animation, styling, binding, etc... public static readonly DependencyProperty TreeViewDataProperty = DependencyProperty.Register("TreeViewData", typeof(List<RegModel>), typeof(Level2PageViewModel));
SelectedItemnearTreeView- BulsonDependencyPropertyview model? This is a game, to be honest. Use normal properties with the implementation ofINotifyPropertyChanged. DependencyProperty` is only suitable for codebeehind, but not for viewmodel. - Bulson