Пример #1
0
        protected override void OnLoad()
        {
            base.OnLoad();

            _dropDownButton = new DropDownButton()
            {
                Width = 150,
            };

            _dropDownButton.CreateControlForItem += (o) =>
            {
                return(new TextBlock()
                {
                    Text = o.ToString(),
                    Font = "Tahoma14Bold",
                });
            };

            _dropDownButton.Properties.Get <int>(DropDownButton.SelectedIndexPropertyId).Changed += (o, args) =>
            {
                if (_parent != null)
                {
                    var propertyInfo = _parent.PropertyInfo;
                    var source       = _parent.Source;

                    var values = Enum.GetValues(propertyInfo.PropertyType);
                    var value  = values.GetValue(args.NewValue);

                    propertyInfo.SetValue(source, value, null);
                }
            };

            var parent = _parent = this.GetAncestors().OfType <PropertyFrame>().FirstOrDefault();

            if (parent != null)
            {
                var propertyInfo = parent.PropertyInfo;
                var source       = parent.Source;

                var values = Enum.GetValues(propertyInfo.PropertyType);

                foreach (var item in values)
                {
                    _dropDownButton.Items.Add(item);
                }

                var value = propertyInfo.GetValue(source);

                _dropDownButton.SelectedIndex = Array.IndexOf(values, value);
            }

            Children.Add(_dropDownButton);
        }
        protected override void OnLoad()
        {
            base.OnLoad();

            _comboBoxButton = new CheckComboBoxButton()
            {
                Width = 150,
            };

            _comboBoxButton.CreateControlForItem += (o) =>
            {
                var caption = o.ToString();

                if (o is Item item)
                {
                    caption = item.DisplayName;
                }

                return(new TextBlock()
                {
                    Text = caption,
                    Font = "Tahoma14Bold",

                    Foreground = Color.Yellow,
                    Shadow = Color.Black,
                });
            };

            var sources = _itemsSource.GetValues();

            foreach (var item in sources)
            {
                _comboBoxButton.Items.Add(item);
            }

            var parent = _parent = this.GetAncestors().OfType <PropertyFrame>().FirstOrDefault();

            if (parent != null)
            {
                var propertyInfo = parent.PropertyInfo;
                var source       = parent.Source;
                var propValue    = propertyInfo.GetValue(source);

                if (propValue is IList values)
                {
                    foreach (var value in values)
                    {
                        var item = sources.FirstOrDefault(i => i.Value == value);

                        if (item != null)
                        {
                            _comboBoxButton.SelectedItems.Add(item);
                        }
                    }
                }
                if (propValue is Direction dir)
                {
                    var item = sources.FirstOrDefault(i => (Direction)i.Value == dir);
                    if (item != null)
                    {
                        _comboBoxButton.SelectedItems.Add(item);
                    }
                }
            }

            Children.Add(_comboBoxButton);

            _comboBoxButton.SelectedItems.CollectionChanged += Update;
        }
Пример #3
0
        protected override void OnLoad()
        {
            base.OnLoad();

            var stackPanel = new StackPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
            };

            var colors = new Color[]
            {
                Color.Red,
                Color.LimeGreen,
                Color.Aqua,
                Color.White
            };

            _sliders = new Slider[4];
            _labels  = new TextBlock[4];

            for (int i = 0; i < 4; i++)
            {
                var sliderPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal,
                };

                sliderPanel.Children.Add(_sliders[i] = new Slider()
                {
                    Width   = 150,
                    Minimum = 0, Maximum = 255,
                });
                sliderPanel.Children.Add(_labels[i] = new TextBlock()
                {
                    Font = "Tahoma14Bold",

                    Foreground = colors[i],
                    Shadow     = Color.Black,

                    Margin = new Vector4F(3, 0, 0, 0)
                });

                stackPanel.Children.Add(sliderPanel);
            }

            Children.Add(stackPanel);

            var parent = _parent = this.GetAncestors().OfType <PropertyFrame>().FirstOrDefault();

            if (parent != null)
            {
                var propertyInfo = parent.PropertyInfo;
                var source       = parent.Source;

                var color = (Color)propertyInfo.GetValue(source);

                _sliders[0].Value = color.R;
                _sliders[1].Value = color.G;
                _sliders[2].Value = color.B;
                _sliders[3].Value = color.A;

                for (int i = 0; i < 4; i++)
                {
                    _sliders[i].Properties.Get <float>(RangeBase.ValuePropertyId).Changed += (o, args) => Update();
                }

                Update();
            }
            else
            {
                throw new Exception("Unable to find parent frame for PropertyEditor");
            }
        }