Пример #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //figure out how wide the treeview is so we can wrap the text
            var typeFace = new System.Windows.Media.Typeface(theTreeView.FontFamily.ToString());
            var ft       = new FormattedText("xxxxxxxxxx", System.Globalization.
                                             CultureInfo.CurrentCulture,
                                             theTreeView.FlowDirection,
                                             typeFace,
                                             theTreeView.FontSize,
                                             theTreeView.Foreground,
                                             VisualTreeHelper.GetDpi(this).PixelsPerDip);

            charsPerLine  = (int)(10 * theTreeView.ActualWidth / ft.Width);
            charsPerLine -= 10; //leave a little margin...the indent is calculated for individual entries


            try
            {
                string    root   = textBox1.Text;
                ModuleUKS parent = (ModuleUKS)base.ParentModule;
                if (!updateFailed)
                {
                    expandedItems.Clear();
                    FindExpandedItems(theTreeView.Items, "");
                }
                updateFailed = false;
                theTreeView.Items.Clear();
                int          childCount = 0;
                int          refCount   = 0;
                List <Thing> uks        = parent.GetTheUKS();
                foreach (Thing t1 in uks)
                {
                    childCount += t1.Children.Count;
                    refCount   += t1.References.Count;
                }
                statusLabel.Content = uks.Count + " Nodes  " + (childCount + refCount) + " Edges";
                Thing t = parent.Labeled(root);
                if (t != null)
                {
                    totalItemCount = 0;
                    TreeViewItem tvi = new TreeViewItem {
                        Header = t.Label
                    };
                    tvi.IsExpanded = true; //always expand the top-level item
                    theTreeView.Items.Add(tvi);
                    totalItemCount++;
                    tvi.MouseRightButtonDown += Tvi_MouseRightButtonDown;
                    AddChildren(t, tvi, 0, t.Label);
                }
                else if (root == "") //search for unattached Things
                {
                    try              //ignore problems of collection modified
                    {
                        foreach (Thing t1 in uks)
                        {
                            if (t1.Parents.Count == 0)
                            {
                                TreeViewItem tvi = new TreeViewItem {
                                    Header = t1.Label
                                };
                                theTreeView.Items.Add(tvi);
                            }
                        }
                    }
                    catch { updateFailed = true; }
                }
            }
            catch
            {
                updateFailed = true;
            }
        }