Example #1
0
 void ShowVisualTree(DependencyObject dObject)
 {
     sb.Append(dObject.ToString());
     sb.Append(Environment.NewLine);
     if (VisualTreeHelper.GetChildrenCount(dObject) > 0)
     {
         for (Int32 i = 0; i < VisualTreeHelper.GetChildrenCount(dObject); i++)
         {
             ShowVisualTree(VisualTreeHelper.GetChild(dObject, i));
         }
     }
 }
Example #2
0
	void DumpTree (DependencyObject root, StringBuilder builder)
	{
		builder.AppendFormat (string.Format ("{0}", root.ToString()));
		if (VisualTreeHelper.GetChildrenCount (root) > 0) {
			builder.Append (" -> { \n");
			for (int i = 0; i < VisualTreeHelper.GetChildrenCount (root); i ++) {
				DumpTree (VisualTreeHelper.GetChild (root, i), builder);
				if (i < VisualTreeHelper.GetChildrenCount (root) - 1)
					builder.Append (",\n");
			}
			builder.Append (" }");
		}
	}
        /// <summary>
        /// Sets the SelectedItemStyle property. This dependency property 
        /// indicates what style is to be used on a selected item.
        /// </summary>
        public static void SetSelectedItemStyle(DependencyObject d, Style value)
        {
            if (!(d is ListBox))
                throw new InvalidCastException(d.ToString() + " is no ListBox");

            var lb = (ListBox)d;

            if (GetSelectedItemStyle(d) == null)
                lb.SelectionChanged += new SelectionChangedEventHandler(lb_SelectionChanged);
            else if (value == null)
                lb.SelectionChanged -= new SelectionChangedEventHandler(lb_SelectionChanged);

            d.SetValue(SelectedItemStyleProperty, value);
        }
Example #4
0
        void ShowLogicTree(DependencyObject dObject)
        {
            sb.Append(dObject.ToString());
            sb.Append(Environment.NewLine);
            foreach (Object d in LogicalTreeHelper.GetChildren(dObject))
            {
                if (d is DependencyObject)
                {
                    ShowLogicTree(d as DependencyObject);
                }
                else
                {
                    sb.Append(d.ToString());
                    sb.Append(Environment.NewLine);
                }

            }
        }
 private static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
 {
     dependencyObject.ToString();
 }
 private Window GetParentWindow(DependencyObject o)
 {
     DependencyObject parent = VisualTreeHelper.GetParent(o);
     if (parent == null)
     {
         FrameworkElement fe = o as FrameworkElement;
         if (fe != null)
         {
             if (fe is Window)
             {
                 return fe as Window;
             }
             else if (fe.Parent != null)
             {
                 return GetParentWindow(fe.Parent);
             }
         }
         throw new ApplicationException("A window parent could not be found for " + o.ToString());
     }
     else
     {
         return GetParentWindow(parent);
     }
 }
        void BuildBackLogicalTree(DependencyObject root)
        {

            if (root == null) return;
            Debug.Write(" - " + String.Format("[{0}]{1}", root.ToString(), (root is FrameworkElement) ? (root as FrameworkElement).Name : ""));

            var parent = LogicalTreeHelper.GetParent(root);

            BuildBackLogicalTree(parent as DependencyObject);
                
            
        }
        void BuildLogicalTree(DependencyObject root, TreeViewItem item)
        {  

            TreeViewItem newItem = new TreeViewItem();
            newItem.Header = String.Format("[{0}]{1}", root.ToString(), (root is FrameworkElement)?(root as FrameworkElement).Name:"");
            newItem.Tag = root;
            if(item!=null)
            {
                item.Items.Add(newItem);
            }
            else
            {
                logicalTreeView.Items.Add(newItem);
            }
            var children = LogicalTreeHelper.GetChildren(root);
            foreach (var child in children)
            {
                if (child is DependencyObject)
                {
                    BuildLogicalTree(child as DependencyObject, newItem);
                }
            }
        }
 void CheckLogicalTree(DependencyObject root)
 {
     var children = LogicalTreeHelper.GetChildren(root);
     foreach (var child in children)
     {
         if (child is DependencyObject)
         {
             if (LogicalTreeHelper.GetParent(child as DependencyObject) != root)
             {
                 Debug.WriteLine(string.Format("Incorrect logical parent in element - {0} in {1}", child.ToString(), root.ToString()));
             }
             CheckLogicalTree(child as DependencyObject);
         }
     }
 }
Example #10
0
        private static bool CheckItem(ItemCollection items, DependencyObject item)
        {
            // See http://www.codeproject.com/KB/menus/WPFMergeMenu.aspx?msg=3827921#xx3827921xx
            foreach (var piece in items)
            {
                string pstr = piece.ToString();
                string istr = item.ToString();
                if (pstr == istr)
                {
                    return true;
                }
            }

            return false;
        }