public void BindItem(PtfPropertyView propertyView)
 {
     if (panels != null)
     {
         //Remove old ItemsControl
         foreach (UIElement i in LayoutRoot.Children)
         {
             var itemsControl = i as ItemsControl;
             if (itemsControl != null && itemsControl.Tag is string && (string)itemsControl.Tag == "PropertyPanel")
             {
                 LayoutRoot.Children.Remove(i);
                 break;
             }
         }
     }
     panels = new List <ItemsControl>();
     GroupList.ItemsSource = propertyView;
     foreach (var p in propertyView)
     {
         panels.Add(CreatePropertyView(p));
     }
     LayoutRoot.Children.Add(panels[0]);
     current = panels[0];
     GroupList.SelectedIndex = 0;
 }
        private ItemsControl CreatePropertyView(PtfPropertyView propertyView)
        {
            var          template     = FindResource("ItemsControlTemplate") as ControlTemplate;
            ItemsControl itemsControl = new ItemsControl()
            {
                Tag    = "PropertyPanel",
                Margin = new Thickness(170, 21, 0, 0),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch,
                Template            = template
            };

            foreach (var item in propertyView)
            {
                if (item.ControlType == Microsoft.Protocols.TestManager.Kernel.ControlType.Group)
                {
                    ExpandGroup eg = new ExpandGroup();
                    eg.Name = item.Name;
                    foreach (var i in item)
                    {
                        eg.AddItem(CreateItem(i, 14));
                    }
                    eg.Associate(itemsControl);
                }
                else
                {
                    itemsControl.Items.Add(CreateItem(item));
                }
            }

            return(itemsControl);
        }
        public void BindItem(PtfPropertyView propertyView)
        {
            if (panels != null)
            {
                //Remove old ItemsControl
                foreach (UIElement i in LayoutRoot.Children)
                {
                    var itemsControl = i as ItemsControl;
                    if (itemsControl != null && itemsControl.Tag is string && (string)itemsControl.Tag == "PropertyPanel")
                    {
                        LayoutRoot.Children.Remove(i);
                        break;
                    }
                }

            }
            panels = new List<ItemsControl>();
            GroupList.ItemsSource = propertyView;
            foreach (var p in propertyView)
            {
                panels.Add(CreatePropertyView(p));
            }
            LayoutRoot.Children.Add(panels[0]);
            current = panels[0];
            GroupList.SelectedIndex = 0;
        }
        private Grid CreateItem(PtfPropertyView propertyView, int indent = 0)
        {
            UIElement content = new Label()
            {
                Content = "Unknown"
            };
            Brush bgbrush = GetBgBrush(propertyView.Value != propertyView.DefaultValue);
            Brush fgbrush = GetFgBrush(propertyView.Value != propertyView.DefaultValue);
            Label label   = new Label()
            {
                Margin              = new Thickness(7 + indent, 0, 0, 0),
                Content             = propertyView.Name + (propertyView.Value == propertyView.DefaultValue ? "" : " *"),
                Width               = NameCollumnWidth - indent,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                Background          = bgbrush,
                Foreground          = fgbrush
            };

            switch (propertyView.ControlType)
            {
            case ControlType.Text:
                var textBox = new TextBox()
                {
                    Margin = new Thickness(NameCollumnWidth + 7, 0, 7, 0),
                    Width  = double.NaN,
                    Text   = propertyView.Value,
                };
                var contextnemu = new TextBoxContextMenu();
                contextnemu.UseDefaultValueClicked += (sender, arg) =>
                {
                    textBox.Text = propertyView.DefaultValue;
                };
                textBox.ContextMenu  = contextnemu;
                textBox.TextChanged += (sender, arg) =>
                {
                    propertyView.Value = textBox.Text;
                };
                content = textBox;
                break;

            case ControlType.Password:
                var passwdTextBox = new TextBox()
                {
                    Margin = new Thickness(NameCollumnWidth + 7, 0, 7, 0),
                    Width  = double.NaN,
                    Text   = propertyView.Value
                };
                passwdTextBox.TextChanged += (sender, arg) =>
                {
                    propertyView.Value = passwdTextBox.Text;
                };
                content = passwdTextBox;
                break;

            case ControlType.Choice:
                var comboBox = new ComboBox()
                {
                    Margin     = new Thickness(NameCollumnWidth + 7, 0, 7, 0),
                    Width      = double.NaN,
                    IsEditable = true
                };
                comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ChoiceItems");
                comboBox.SetBinding(ComboBox.TextProperty, "Value");
                comboBox.DataContext = propertyView;
                content = comboBox;
                break;
            }
            propertyView.PropertyChanged += (sender, arg) =>
            {
                bool modified = propertyView.Value != propertyView.DefaultValue;
                label.Content    = propertyView.Name + (modified ? " *" : "");
                label.Background = GetBgBrush(modified);
                label.Foreground = GetFgBrush(modified);
            };
            Grid grid = new Grid()
            {
                Margin   = new Thickness(0, 1, 0, 1),
                Children =
                {
                    label,
                    content
                },
                ToolTip = propertyView.ToolTip + Environment.NewLine + propertyView.Description
            };

            return(grid);
        }
 /// <summary>
 /// Creates a PtfPropertyView for the UI.
 /// </summary>
 /// <returns>A PtfPropertyView object</returns>
 public PtfPropertyView CreatePtfPropertyView()
 {
     ptfPropertyView = ptfconfig.CreatePtfPropertyView(hiddenProperties);
     if (appConfig.PropertyGroupOrder != null) ptfPropertyView.SortItems(appConfig.PropertyGroupOrder);
     return ptfPropertyView;
 }
        private Grid CreateItem(PtfPropertyView propertyView, int indent = 0)
        {
            UIElement content = new Label() { Content = "Unknown" };
            Brush bgbrush = GetBgBrush(propertyView.Value != propertyView.DefaultValue);
            Brush fgbrush = GetFgBrush(propertyView.Value != propertyView.DefaultValue);
            Label label = new Label()
            {
                Margin = new Thickness(7 + indent, 0, 0, 0),
                Content = propertyView.Name + (propertyView.Value == propertyView.DefaultValue ? "" : " *"),
                Width = NameCollumnWidth - indent,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                Background = bgbrush,
                Foreground = fgbrush
            };
            switch (propertyView.ControlType)
            {
                case ControlType.Text:
                    var textBox = new TextBox()
                    {
                        Margin = new Thickness(NameCollumnWidth + 7, 0, 7, 0),
                        Width = double.NaN,
                        Text = propertyView.Value,
                    };
                    var contextnemu = new TextBoxContextMenu();
                    contextnemu.UseDefaultValueClicked += (sender, arg) =>
                    {
                        textBox.Text = propertyView.DefaultValue;
                    };
                    textBox.ContextMenu = contextnemu;
                    textBox.TextChanged += (sender, arg) =>
                        {
                            propertyView.Value = textBox.Text;
                        };
                    content = textBox;
                    break;
                case ControlType.Password:
                    var passwdTextBox = new TextBox()
                    {
                        Margin = new Thickness(NameCollumnWidth + 7, 0, 7, 0),
                        Width = double.NaN,
                        Text = propertyView.Value
                    };
                    passwdTextBox.TextChanged += (sender, arg) =>
                    {
                        propertyView.Value = passwdTextBox.Text;
                    };
                    content = passwdTextBox;
                    break;
                case ControlType.Choice:
                    var comboBox = new ComboBox()
                    {
                        Margin = new Thickness(NameCollumnWidth + 7, 0, 7, 0),
                        Width = double.NaN,
                        IsEditable = true
                    };
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ChoiceItems");
                    comboBox.SetBinding(ComboBox.TextProperty, "Value");
                    comboBox.DataContext = propertyView;
                    content = comboBox;
                    break;
            }
            propertyView.PropertyChanged += (sender, arg) =>
            {
                bool modified = propertyView.Value != propertyView.DefaultValue;
                label.Content = propertyView.Name + (modified ? " *" : "");
                label.Background = GetBgBrush(modified);
                label.Foreground = GetFgBrush(modified);
            };
            Grid grid = new Grid()
                {
                    Margin = new Thickness(0, 1, 0, 1),
                    Children =
                    {
                        label,
                        content
                    },
                    ToolTip = propertyView.ToolTip + Environment.NewLine + propertyView.Description
                };

            return grid;
        }
        private ItemsControl CreatePropertyView(PtfPropertyView propertyView)
        {
            var template = FindResource("ItemsControlTemplate") as ControlTemplate;
            ItemsControl itemsControl = new ItemsControl()
            {
                Tag = "PropertyPanel",
                Margin = new Thickness(170, 21, 0, 0),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
                Template = template
            };
            foreach (var item in propertyView)
            {
                if (item.ControlType == Microsoft.Protocols.TestManager.Kernel.ControlType.Group)
                {
                    ExpandGroup eg = new ExpandGroup();
                    eg.Name = item.Name;
                    foreach (var i in item)
                    {
                        eg.AddItem(CreateItem(i, 14));
                    }
                    eg.Associate(itemsControl);
                }
                else
                {
                    itemsControl.Items.Add(CreateItem(item));
                }
            }

            return itemsControl;
        }
 public TreeStackItem(PtfProperty node, PtfPropertyView view)
 {
     PropertyNode = node;
     PropertyView = view;
     Path = new List<string>();
 }
        /// <summary>
        /// Creates PtfPropertyView
        /// </summary>
        /// <param name="hideProperties">Hide properties.</param>
        /// <returns>An instance of PtfPropertyView</returns>
        public PtfPropertyView CreatePtfPropertyView(List<string> hideProperties)
        {
            List<PtfProperty> hide = new List<PtfProperty>();
            foreach (string name in hideProperties)
            {
                PtfProperty p = GetPropertyNodeByName(name);
                if (p != null) hide.Add(p);
            }

            // Root Group
            PtfPropertyRoot.ValueType = PtfPropertyType.Group;
            PtfPropertyView propertyView = new PtfPropertyView(PtfPropertyRoot);
            Stack<TreeStackItem> propertyStack = new Stack<TreeStackItem>();
            propertyStack.Push(new TreeStackItem(PtfPropertyRoot, propertyView));

            while (propertyStack.Count > 0)
            {
                TreeStackItem p = propertyStack.Pop();

                if (p.PropertyNode.ValueType != PtfPropertyType.Group)
                {
                    if (hide.Contains(p.PropertyNode)) continue;
                    var view = new PtfPropertyView(p.PropertyNode, p.PathFrom(3));
                    p.PropertyView.Add(view);
                }
                else
                {
                    PtfPropertyView view;
                    if (p.Path.Count <= 2)
                    {
                        view = new PtfPropertyView(p.PropertyNode);
                        p.PropertyView.Add(view);
                    }
                    else view = p.PropertyView;
                    for (int i = p.PropertyNode.Count - 1; i >= 0; i--)
                    {
                        var child = p.PropertyNode[i];
                        TreeStackItem c = new TreeStackItem(
                            child,
                            view);
                        c.Path.InsertRange(0, p.Path);
                        c.Path.Add(p.PropertyNode.Name);
                        propertyStack.Push(c);
                    }
                }
            }

            var v = propertyView[0];
            // Remove empty view
            for (int i = 0; i < v.Count; i++)
            {
                if (v[i].IsEmptyGroup)
                {
                    v.RemoveAt(i);
                    i--;
                    continue;
                }
                var childv = v[i];
                for (int ii = 0; ii < childv.Count; ii++)
                {
                    if (childv[ii].IsEmptyGroup)
                    {
                        childv.RemoveAt(ii);
                        ii--;
                    }
                }
            }
            return v;
        }