// Define the Convert method to convert a DateTime value to // a month string. public static TreeViewSelectionMode IsRunningToSelectionMode(bool value) { // value is the data from the source object. TreeViewSelectionMode SelectionMode = value ? TreeViewSelectionMode.None : TreeViewSelectionMode.Single; return(SelectionMode); }
private void OnPropertyChanged(DependencyPropertyChangedEventArgs args) { DependencyProperty property = args.Property; if (property == SelectionModeProperty && ListControl != null) { TreeViewSelectionMode value = SelectionMode; switch (value) { case TreeViewSelectionMode.None: { ListControl.SelectionMode = ListViewSelectionMode.None; UpdateItemsSelectionMode(false); } break; case TreeViewSelectionMode.Single: { ListControl.SelectionMode = ListViewSelectionMode.Single; UpdateItemsSelectionMode(false); } break; case TreeViewSelectionMode.Multiple: { ListControl.SelectionMode = ListViewSelectionMode.None; UpdateItemsSelectionMode(true); } break; } } else if (property == ItemsSourceProperty) { m_rootNode.IsContentMode = true; if (ListControl != null) { var viewModel = ListControl.ListViewModel; viewModel.IsContentMode = true; } m_rootNode.ItemsSource = ItemsSource; } else if (property == SelectedItemProperty) { var items = SelectedItems; var selected = items?.Count > 0 ? items[0] : null; if (args.NewValue != selected) { ListControl?.ListViewModel?.SelectSingleItem(args.NewValue); } } }
public static void SetSelectionMode(TreeView TreeView, TreeViewSelectionMode Value) { TreeView.SetValue(SelectionModeProperty, Value); }