/// <summary>
        /// Creates a StackPanel item.
        /// </summary>
        /// <param name="parent"> The control that was expanded. </param>
        /// <param name="name"> The property name. </param>
        /// <param name="value"> The property value (as a string). </param>
        /// <param name="key"> A key that can be used to retrieve further properties. </param>
        /// <param name="valueColor"> The color to use for the value. </param>
        /// <returns> A control that should be inserted into the Items collection. </returns>
        private Control CreateControl(ExpanderButton parent, string name, string value, object key, Color valueColor)
        {
            // Create the content portion.
            var content = new TextBlock();

            if (name == null)
            {
                content.Inlines.Add(new Run()
                {
                    Text = value
                });
            }
            else
            {
                content.Inlines.Add(new Run()
                {
                    Foreground = new SolidColorBrush(Colors.Purple), Text = name
                });
                content.Inlines.Add(new Run()
                {
                    Foreground = new SolidColorBrush(valueColor), Text = ": " + value
                });
            }

            // Create tag information to attach to the control.
            var tagInfo = new TagInfo();

            tagInfo.Key    = key;
            tagInfo.Parent = parent;

            // Calculate the left margin.
            var leftMargin = parent == null ? 0 : parent.Margin.Left + 8;

            // Use an expander if the value is an object.
            if (key != null)
            {
                var result = new ExpanderButton();
                result.Margin     = new Thickness(leftMargin, 0, 0, 0);
                result.Tag        = tagInfo;
                result.Content    = content;
                result.Checked   += new RoutedEventHandler(OnChecked);
                result.Unchecked += new RoutedEventHandler(OnUnchecked);
                return(result);
            }
            else
            {
                var result = new ContentControl();
                result.Content = content;
                result.Margin  = new Thickness(leftMargin + 16, 0, 0, 0);
                result.Tag     = tagInfo;
                return(result);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines if a control is a logical child of another control.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="ancestor"></param>
 /// <returns></returns>
 private static bool HasAncestor(FrameworkElement child, ExpanderButton ancestor)
 {
     while (true)
     {
         var parent = ((TagInfo)child.Tag).Parent;
         if (parent == null)
             return false;
         if (parent == ancestor)
             return true;
         child = parent;
     }
 }
 /// <summary>
 /// Determines if a control is a logical child of another control.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="ancestor"></param>
 /// <returns></returns>
 private static bool HasAncestor(FrameworkElement child, ExpanderButton ancestor)
 {
     while (true)
     {
         var parent = ((TagInfo)child.Tag).Parent;
         if (parent == null)
         {
             return(false);
         }
         if (parent == ancestor)
         {
             return(true);
         }
         child = parent;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a StackPanel item.
        /// </summary>
        /// <param name="parent"> The control that was expanded. </param>
        /// <param name="name"> The property name. </param>
        /// <param name="value"> The property value (as a string). </param>
        /// <param name="key"> A key that can be used to retrieve further properties. </param>
        /// <param name="valueColor"> The color to use for the value. </param>
        /// <returns> A control that should be inserted into the Items collection. </returns>
        private Control CreateControl(ExpanderButton parent, string name, string value, object key, Color valueColor)
        {
            // Create the content portion.
            var content = new TextBlock();
            if (name == null)
            {
                content.Inlines.Add(new Run() { Text = value });
            }
            else
            {
                content.Inlines.Add(new Run() { Foreground = new SolidColorBrush(Colors.Purple), Text = name });
                content.Inlines.Add(new Run() { Foreground = new SolidColorBrush(valueColor), Text = ": " + value });
            }

            // Create tag information to attach to the control.
            var tagInfo = new TagInfo();
            tagInfo.Key = key;
            tagInfo.Parent = parent;

            // Calculate the left margin.
            var leftMargin = parent == null ? 0 : parent.Margin.Left + 8;

            // Use an expander if the value is an object.
            if (key != null)
            {
                var result = new ExpanderButton();
                result.Margin = new Thickness(leftMargin, 0, 0, 0);
                result.Tag = tagInfo;
                result.Content = content;
                result.Checked += new RoutedEventHandler(OnChecked);
                result.Unchecked += new RoutedEventHandler(OnUnchecked);
                return result;
            }
            else
            {
                var result = new ContentControl();
                result.Content = content;
                result.Margin = new Thickness(leftMargin + 16, 0, 0, 0);
                result.Tag = tagInfo;
                return result;
            }
        }