Пример #1
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);
        }
        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;
        }