Пример #1
0
        private static ITreeViewItemModel GetFind(List <ITreeViewItemModel> currentItems, string hierarchy)
        {
            ITreeViewItemModel selectedItem = null;

            if (hierarchy != null && hierarchy.Length > 0)
            {
                for (int i = 0; i < currentItems.Count; i++)
                {
                    if (currentItems[i].SelectedValuePath == hierarchy)
                    {
                        selectedItem = currentItems[i];
                        break;
                    }


                    selectedItem = GetFind(currentItems[i].GetChildren().ToList(), hierarchy);

                    if (selectedItem != null)
                    {
                        break;
                    }
                }
            }
            return(selectedItem);
        }
Пример #2
0
        public TreeViewItemViewModelBase(string value, ITreeViewItemModel parent, IEnumerable <ITreeViewItemModel> children = null)
        {
            Value        = value;
            Parent       = parent;
            Children     = new ObservableCollection <ITreeViewItemModel>(children ?? Enumerable.Empty <ITreeViewItemModel>());
            CheckCommand = ReactiveCommand.Create(SetChecked);

            this.WhenAnyValue(x => x.IsChecked).Subscribe(x => SpecificLogic(x));
        }
Пример #3
0
        /// <summary>
        /// Searches the items of the hierarchy inside the items source and selects the last found item
        /// </summary>
        private static ITreeViewItemModel SelectItem(IEnumerable <ITreeViewItemModel> items, IEnumerable <string> selectedHierarchy)
        {
            if (items == null || selectedHierarchy == null || !items.Any() || !selectedHierarchy.Any())
            {
                return(null);
            }

            var hierarchy    = selectedHierarchy.ToList();
            var currentItems = items;
            ITreeViewItemModel selectedItem = null;

            for (int i = 0; i < hierarchy.Count; i++)
            {
                // get next item in the hierarchy from the collection of child items
                var currentItem = currentItems.FirstOrDefault(ci => ci.SelectedValuePath == hierarchy[i]);
                if (currentItem == null)
                {
                    break;
                }

                selectedItem = currentItem;

                // rewrite the current collection of child items
                currentItems = selectedItem.GetChildren();
                if (currentItems == null)
                {
                    break;
                }

                // the intermediate items will be expanded
                if (i != hierarchy.Count - 1)
                {
                    selectedItem.IsExpanded = true;
                }
            }

            if (selectedItem != null)
            {
                selectedItem.IsSelected = true;
            }

            return(selectedItem);
        }