예제 #1
0
        public ValueControl GetControl(InspectableProperty property)
        {
            TextBox control = new TextBox();

            control.Padding = new Thickness(2, 2, 2, 2);

            //Create a suspendable binding
            SuspendableProperty dataSource = new SuspendableProperty(property);
            //Dispose of dataSource if the control is unloaded
            //control.Unloaded += (s,e) => { dataSource.Dispose(); };
            //Create two way binding
            Binding twoWayBinding = new Binding();

            twoWayBinding.Source = dataSource;
            twoWayBinding.Path   = new PropertyPath(nameof(SuspendableProperty.PropertyValue));
            twoWayBinding.Mode   = BindingMode.TwoWay;
            twoWayBinding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;
            twoWayBinding.Converter           = GetConverter(property);

            //Set up edit events
            Action resumeBinding = () => {
                dataSource.SuspendIncomming = false;
            };

            Action suspendBinding = () =>
            {
                dataSource.SuspendIncomming = true;
            };

            //We default to using the two way
            BindingOperations.SetBinding(control, TextBox.TextProperty, twoWayBinding);
            return(new ValueControl(control, EditingBehaviour.OnFocus, suspendBinding, resumeBinding));
        }
예제 #2
0
        public ValueControl GetControl(InspectableProperty property)
        {
            ComboBox control = new ComboBox();

            control.Padding = new Thickness(5, 3, 2, 2);

            string[] values = GetValues(property.ReflectionData);
            control.ItemsSource = values;

            Binding binding = new Binding();

            binding.Source = property.Target;
            binding.Path   = new PropertyPath(property.ReflectionData.Name);
            binding.Mode   = BindingMode.TwoWay;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;

            if (property.ReflectionData.PropertyType.IsEnum)
            {
                binding.Converter = new EnumToStringConverter();
            }
            else if (property.ReflectionData.PropertyType == typeof(bool))
            {
                binding.Converter = new BoolToStringConverter();
            }

            //Set the binding
            BindingOperations.SetBinding(control, ComboBox.SelectedValueProperty, binding);

            return(new ValueControl(control, EditingBehaviour.OnFocus));
        }
예제 #3
0
 private IValueConverter GetConverter(InspectableProperty property)
 {
     if (property.ReflectionData.PropertyType == typeof(double))
     {
         return(new DoubleToStringConverter());
     }
     else if (property.ReflectionData.PropertyType == typeof(int))
     {
         return(new IntToStringConverter());
     }
     //no converter used for other types
     return(null);
 }