private void LoadTreeView(SearchableTreeNode fullTree)
        {
            // This happens when there are no search results.
            if (fullTree == null)
            {
                return;
            }
            CategoriesTree.RootNodes.Clear();

            muxc.TreeViewNode rootNode;

            foreach (SearchableTreeNode category in fullTree.Items)
            {
                rootNode = new muxc.TreeViewNode()
                {
                    Content = category
                };
                category.Items.ForEach(info => rootNode.Children.Add(new muxc.TreeViewNode()
                {
                    Content = info
                }));

                CategoriesTree.RootNodes.Add(rootNode);
            }
        }
Exemple #2
0
        private void InitializeSampleTreeView2()
        {
            mux.TreeViewNode workFolder = new mux.TreeViewNode()
            {
                Content = "Work Documents"
            };
            workFolder.IsExpanded = true;

            workFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "XYZ Functional Spec"
            });
            workFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Feature Schedule"
            });
            workFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Overall Project Plan"
            });
            workFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Feature Resources Allocation"
            });

            mux.TreeViewNode remodelFolder = new mux.TreeViewNode()
            {
                Content = "Home Remodel"
            };
            remodelFolder.IsExpanded = true;

            remodelFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Contractor Contact Info"
            });
            remodelFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Paint Color Scheme"
            });
            remodelFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Flooring woodgrain type"
            });
            remodelFolder.Children.Add(new mux.TreeViewNode()
            {
                Content = "Kitchen cabinet style"
            });

            personalFolder2 = new mux.TreeViewNode()
            {
                Content = "Personal Documents"
            };
            personalFolder2.IsExpanded = true;
            personalFolder2.Children.Add(remodelFolder);

            sampleTreeView2.RootNodes.Add(workFolder);
            sampleTreeView2.RootNodes.Add(personalFolder2);
        }
        private async void CategoriesTree_ItemInvoked(muxc.TreeView sender, muxc.TreeViewItemInvokedEventArgs e)
        {
            muxc.TreeViewNode selected = (muxc.TreeViewNode)e.InvokedItem;

            if (selected.Content.GetType() == typeof(SearchableTreeNode))
            {
                SamplePageContainer.Visibility = Visibility.Collapsed;
                SampleSelectionGrid.Visibility = Visibility.Visible;
                List <SampleInfo> samples = selected.Children.ToList().Select(x => (SampleInfo)x.Content).ToList();
                SamplesGridView.ItemsSource = samples;
            }
            else if (selected.Content.GetType() == typeof(SampleInfo))
            {
                await SelectSample((SampleInfo)selected.Content);
            }
        }
 public MainPage()
 {
     this.InitializeComponent();
     for (byte b1 = 0; b1 < 20; b1++)
     {
         muxc.TreeViewNode rootnode = new muxc.TreeViewNode()
         {
             Content = $"parent item {b1}"
         };
         for (byte b2 = 0; b2 < 8; b2++)
         {
             rootnode.Children.Add(new muxc.TreeViewNode()
             {
                 Content = $"child item {b1},{b2}"
             });
         }
         TvTree2.RootNodes.Add(rootnode);
     }
 }
Exemple #5
0
    public async System.Threading.Tasks.Task OpenTreeView(ViewModels.FileItemViewModel fv)
    {
        var list = new Stack <ViewModels.FileItemViewModel>();
        var cfv  = fv;

        while (cfv != null)
        {
            list.Push(cfv);
            cfv = cfv.Parent;
        }

        var cnode = treeview.RootNodes;

        winui.TreeViewNode ctreenode = null;
        foreach (var item in list)
        {
            var ctreenodeTmp = cnode.FirstOrDefault(a => a.Content is ViewModels.FileItemViewModel fv2 && (fv2 == item || fv2.Content == item.Content));
            if (ctreenodeTmp is null)
            {
                continue;
            }
            ctreenode = ctreenodeTmp;
            if (ctreenode.Content is ViewModels.FileItemViewModel fvm && fvm.Children is null)
            {
                await fvm.UpdateChildren();
            }
            ctreenode.IsExpanded = true;
            treeview.Expand(ctreenode);
            cnode = ctreenode.Children;
        }
        //You can't get item in single selection mode before Microsoft.UI.Xaml v2.2.190731001-prerelease.
        //See.
        //https://github.com/microsoft/microsoft-ui-xaml/pull/243
        //So treeview is replaced by WinUI version.

        treeview.SelectedNode = ctreenode;

        //Maybe you can scroll...
        //See.
        //https://stackoverflow.com/questions/52015723/uwp-winui-treeview-programatically-scroll-to-item
        //But well... I dont like this.
    }
        private async Task FillNode(MUXC.TreeViewNode node)
        {
            if (node is CancellableTreeViewNode ctvn && node.Content is CheckList list && node.HasUnrealizedChildren)
            {
                CancellationToken token = ctvn.TokenSource.Token;

                ctvn.IsWorking = true;
                bool finished = await FillNodeListWithData(node.Children, list, token);

                ctvn.IsWorking = false;

                if (finished)
                {
                    node.HasUnrealizedChildren = false;
                }
                else
                {
                    node.HasUnrealizedChildren = true;
                }
            }
        }
 private MUXC.TreeViewNode CreatePointNode(CheckPoint point)
 {
     MUXC.TreeViewNode newNode = new MUXC.TreeViewNode();
     newNode.Content = point;
     return(newNode);
 }
        private object GetAt(int index)
        {
            TreeViewNode node = GetNodeAt(index);

            return(IsContentMode ? node.Content : node);
        }
 internal void ExpandNode(TreeViewNode value)
 {
     value.IsExpanded = true;
 }
Exemple #10
0
        private int IndexInParent(TreeViewNode node)
        {
            int indexInParent = node.Parent.Children.IndexOf(node);

            return(indexInParent);
        }
Exemple #11
0
 internal object ItemFromNode(TreeViewNode node)
 {
     return((IsContentMode && node != null) ? node.Content : node);
 }
Exemple #12
0
        protected override void OnDragOver(Windows.UI.Xaml.DragEventArgs args)
        {
            if (!args.Handled)
            {
                args.AcceptedOperation = DataPackageOperation.None;
                IInsertionPanel insertionPanel = (IInsertionPanel)ItemsPanelRoot;

                // reorder is only supported with panels that implement IInsertionPanel
                if (insertionPanel != null && m_draggedTreeViewNode != null && CanReorderItems)
                {
                    int aboveIndex  = -1;
                    int belowIndex  = -1;
                    var itemsSource = ListViewModel;
                    int size        = itemsSource.Count;
                    var point       = args.GetPosition((UIElement)insertionPanel);
                    insertionPanel.GetInsertionIndexes(point, out aboveIndex, out belowIndex);

                    // a value of -1 means we're inserting at the end of the list or before the last item
                    if (belowIndex == -1)
                    {
                        // this allows the next part of this code to test if we're dropping before or after the last item
                        belowIndex = size - 1;
                    }

                    // if we have an insertion point
                    // a value of 0 means we're inserting at the beginning
                    // a value greater than size - 1 means we're inserting at the end as items are collapsing
                    if (belowIndex > size - 1)
                    {
                        // don't go out of bounds
                        // since items might be collapsing as we're dragging
                        m_emptySlotIndex = size - 1;
                    }
                    else if (belowIndex > 0 && m_draggedTreeViewNode != null)
                    {
                        m_emptySlotIndex = -1;
                        TreeViewNode tvi = m_draggedTreeViewNode;
                        if (ListViewModel.IndexOfNode(tvi, out var draggedIndex))
                        {
                            int indexToUse = (draggedIndex < belowIndex) ? belowIndex : (belowIndex - 1);
                            var item       = ContainerFromIndex(indexToUse);
                            if (item != null)
                            {
                                var treeViewItem    = (TreeViewItem)item;
                                var pointInsideItem = args.GetPosition(treeViewItem);

                                // if the point is in the top half of the item
                                // we need to insert before that item
                                if (pointInsideItem.Y < treeViewItem.ActualHeight / 2)
                                {
                                    m_emptySlotIndex = belowIndex - 1;
                                }
                                else
                                {
                                    m_emptySlotIndex = belowIndex;
                                }
                            }
                        }
                    }
                    else
                    {
                        // top of the list
                        m_emptySlotIndex = 0;
                    }

                    bool allowReorder = true;
                    if (IsFlatIndexValid(m_emptySlotIndex))
                    {
                        var insertAtNode = NodeAtFlatIndex(m_emptySlotIndex);
                        if (IsMultiselect)
                        {
                            // If insertAtNode is in the selected items, then we do not want to allow a dropping.
                            var selectedItems = ListViewModel.SelectedNodes;
                            for (var i = 0; i < selectedItems.Count; i++)
                            {
                                var selectedNode = selectedItems[i];
                                if (selectedNode == insertAtNode)
                                {
                                    allowReorder = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (m_draggedTreeViewNode != null && insertAtNode != null && insertAtNode.Parent != null)
                            {
                                var insertContainer = ContainerFromNode(insertAtNode.Parent);
                                if (insertContainer != null)
                                {
                                    allowReorder = ((TreeViewItem)insertContainer).AllowDrop;
                                }
                            }
                        }
                    }
                    else
                    {
                        // m_emptySlotIndex does not exist in the ViewModel - don't allow the reorder.
                        allowReorder = false;
                    }

                    if (allowReorder)
                    {
                        args.AcceptedOperation = DataPackageOperation.Move;
                    }
                    else
                    {
                        m_emptySlotIndex       = -1;
                        args.AcceptedOperation = DataPackageOperation.None;
                        args.Handled           = true;
                    }
                }

                UpdateDropTargetDropEffect(false, false, null);
            }
            base.OnDragOver(args);
        }
Exemple #13
0
 private void OnDragItemsCompleted(object sender, DragItemsCompletedEventArgs args)
 {
     m_draggedTreeViewNode = null;
     m_emptySlotIndex      = -1;
 }
Exemple #14
0
        private async Task <FolderItem> CreateFolderWithSelectedAsParentAsync(string name)
        {
            try
            {
                var folderItem = await FolderItem.GetNew(name);

                if (GetSelectedFolder() != null)
                {
                    try
                    {
                        await folderItem.SetParentAsync(GetSelectedFolder());
                    }
                    catch (Exception exception)
                    {
                        var messageDialog = new MessageDialog("Error setting folder parent: " + exception.Message);
                        messageDialog.Commands.Add(new UICommand("Close"));
                        messageDialog.DefaultCommandIndex = 0;
                        messageDialog.CancelCommandIndex  = 0;
                        await messageDialog.ShowAsync();

                        await folderItem.DeleteAsync();

                        return(null);
                    }
                }

                var newNode = new WinUI.TreeViewNode()
                {
                    Content = folderItem
                };

                if (GetSelectedNode() != null)
                {
                    GetSelectedNode().Children.Add(newNode);
                    treeView.Expand(GetSelectedNode());
                }
                else
                {
                    treeView.RootNodes.Add(newNode);
                }

                SelectNode(newNode);
                await Task.Delay(100);

                var container = treeView.ContainerFromNode(newNode);

                if (container != null)
                {
                    var tvi = container as WinUI.TreeViewItem;
                    (tvi?.Content as EditableTextBlock)?.EnableEditMode();
                }

                return(folderItem);
            }
            catch (Exception exception)
            {
                var messageDialog = new MessageDialog("Error: " + exception.Message);
                messageDialog.Commands.Add(new UICommand("Close"));
                messageDialog.DefaultCommandIndex = 0;
                messageDialog.CancelCommandIndex  = 0;
                await messageDialog.ShowAsync();

                return(null);
            }
        }
Exemple #15
0
 private void SelectNode(WinUI.TreeViewNode node)
 {
     treeView.SelectedNodes.Clear();
     treeView.SelectedNodes.Add(node);
     SelectedNode = node;
 }
Exemple #16
0
 internal void CollapseNode(TreeViewNode value)
 {
     value.IsExpanded = false;
 }