Exemplo n.º 1
0
 private static DirectBinding <T> Convert <T>(this DirectBinding <PluginSetting> binding, PropertyInfo property)
 {
     return(binding.Convert(
                s => s.GetValueOrDefault <T>(property),
                v => new PluginSetting(property, v)
                ));
 }
Exemplo n.º 2
0
        private static TControl GetMaskedTextBox <TControl, T>(PropertyInfo property, DirectBinding <PluginSetting> binding) where TControl : MaskedTextBox <T>, new()
        {
            var textBox = new TControl();

            textBox.ValueBinding.Bind(binding.Convert <T>(property));
            return(textBox);
        }
                protected override Control CreateControl(DirectBinding <byte> keyBinding, DirectBinding <string> valueBinding)
                {
                    var keyBox = new IntegerNumberBox();

                    keyBox.ValueBinding.Bind(keyBinding.Convert(
                                                 b => (int)b,
                                                 i => (byte)i
                                                 ));
                    keyBox.TextChanging += (sender, e) => e.Cancel = byte.TryParse(e.NewText, out byte newByte) && ItemSource.Keys.Contains(newByte);

                    var valueBox = new TextBox();

                    valueBox.TextBinding.Bind(valueBinding);

                    return(new StackLayout
                    {
                        Orientation = Orientation.Horizontal,
                        Padding = new Padding(0, 0, 5, 0),
                        Spacing = 5,
                        Items =
                        {
                            keyBox,
                            new StackLayoutItem(valueBox, true)
                        }
                    });
                }
                protected override Control CreateControl(int index, DirectBinding <byte> itemBinding)
                {
                    MaskedTextBox <int> intBox = new IntegerNumberBox();

                    intBox.ValueBinding.Bind(
                        itemBinding.Convert <int>(
                            c => (int)c,
                            v => (byte)v
                            )
                        );

                    return(new Panel
                    {
                        Padding = new Padding(0, 0, 5, 0),
                        Content = intBox
                    });
                }
Exemplo n.º 5
0
        private static Control GetControlForSetting(PropertyInfo property, DirectBinding <PluginSetting> binding)
        {
            if (property.PropertyType == typeof(string))
            {
                if (property.GetCustomAttribute <PropertyValidatedAttribute>() is PropertyValidatedAttribute validateAttr)
                {
                    var comboBox = new DropDown <string>
                    {
                        DataStore = validateAttr.GetValue <IEnumerable <string> >(property),
                    };
                    comboBox.SelectedItemBinding.Bind(binding.Convert <string>(property));
                    return(comboBox);
                }
                else
                {
                    var textBox = new TextBox();
                    textBox.TextBinding.Bind(binding.Convert <string>(property));
                    return(textBox);
                }
            }
            else if (property.PropertyType == typeof(bool))
            {
                string description = property.Name;
                if (property.GetCustomAttribute <BooleanPropertyAttribute>() is BooleanPropertyAttribute attribute)
                {
                    description = attribute.Description;
                }

                var checkbox = new CheckBox
                {
                    Text = description
                };
                checkbox.CheckedBinding.Cast <bool>().Bind(
                    binding.Convert(
                        s => s.GetValueOrDefault <bool>(property),
                        v => new PluginSetting(property, v)
                        )
                    );
                return(checkbox);
            }
            else if (property.PropertyType == typeof(float))
            {
                var tb = GetMaskedTextBox <FloatNumberBox, float>(property, binding);

                if (property.GetCustomAttribute <SliderPropertyAttribute>() is SliderPropertyAttribute sliderAttr)
                {
                    // TODO: replace with slider when possible (https://github.com/picoe/Eto/issues/1772)
                    tb.ToolTip         = $"Minimum: {sliderAttr.Min}, Maximum: {sliderAttr.Max}";
                    tb.PlaceholderText = $"{sliderAttr.DefaultValue}";

                    if (!binding.DataValue.HasValue)
                    {
                        binding.DataValue.SetValue(sliderAttr.DefaultValue);
                    }
                }
                return(tb);
            }
            else if (genericControls.TryGetValue(property.PropertyType, out var getGenericTextBox))
            {
                return(getGenericTextBox(property, binding));
            }
            throw new NotSupportedException($"'{property.PropertyType}' is not supported for generated controls.");
        }