コード例 #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="CsvTableDataLoader" /> class.
 /// </summary>
 /// <param name="file"> The file reference to the CSV file. </param>
 /// <param name="table"> The metadata of the requested table. </param>
 public CsvTableDataLoader(IFileReference file, TableDescription table) 
     : base(table)
 {
     // TODO: Constructor injection
     this.valueConverter = new CsvValueConverter();
     this.file = file;
 }
コード例 #2
0
 public EncryptingValueConverter(
     IValueConverter decoratedValueConverter,
     IEncryptionAlgorithmFactory encryptionAlgorithmFactory)
 {
     _decoratedValueConverter = decoratedValueConverter;
     _encryptionAlgorithm = encryptionAlgorithmFactory.GetAlgorithm(decoratedValueConverter.Type);
 }
コード例 #3
0
        public static IEnumerable<EnumMemberInfo> GetEnumSource(Type enumType, bool useUnderlyingEnumValue = true, IValueConverter nameConverter = null, bool splitNames = false, EnumMembersSortMode sortMode = EnumMembersSortMode.Default, Func<string, bool, string> getKnownImageUriCallback = null, bool showImage = true, bool showName = true) {
            var result = enumType.GetFields(BindingFlags.Static | BindingFlags.Public)
                .Where(field => DataAnnotationsAttributeHelper.GetAutoGenerateField(field))
                .Select(field => {
                    Enum value = (Enum)field.GetValue(null);
                    string name = GetEnumName(field, value, nameConverter, splitNames);

                    var imageInfo = GetImageInfo(MetadataHelper.GetAttribute<ImageAttribute>(field), MetadataHelper.GetAttribute<DXImageAttribute>(field), null, getKnownImageUriCallback);
                    ImageSource image = ViewModelBase.IsInDesignMode ? null : (imageInfo.Item1 ?? imageInfo.Item2).With(x => (ImageSource)new ImageSourceConverter().ConvertFrom(x));
                    return new EnumMemberInfo(name, DataAnnotationsAttributeHelper.GetFieldDescription(field), useUnderlyingEnumValue ? GetUnderlyingEnumValue(value) : value, image, showImage, showName,
                     DataAnnotationsAttributeHelper.GetFieldOrder(field));
                });
            switch(sortMode) {
                case EnumMembersSortMode.DisplayName:
                    result = result.OrderBy(x => x.Name);
                    break;
                case EnumMembersSortMode.DisplayNameDescending:
                    result = result.OrderByDescending(x => x.Name);
                    break;
                case EnumMembersSortMode.DisplayNameLength:
                    result = result.OrderBy(x => x.Name.Length);
                    break;
                case EnumMembersSortMode.DisplayNameLengthDescending:
                    result = result.OrderByDescending(x => x.Name.Length);
                    break;
            }
            return result.OrderBy(x => (x.Order != null) ? x.Order : DefaultDisplayOrder).ToArray();
        }
コード例 #4
0
 public ChangeObjectValueAction(BoundPropertyDescriptor boundPropertyDescriptor, object originalValue, object newValue, IValueConverter stringConverter)
 {
     _boundPropertyDescriptor = boundPropertyDescriptor;
     _originalValue = originalValue;
     _newValue = newValue;
     _stringConverter = stringConverter;
 }
コード例 #5
0
 static EditCellFactory()
 {
     AddressConverter = new AddressToPositionConverter();
     AddressToStringConverter = new AddressToStringConverter();
     OwnerConverter = new UserConverter();
     DefaultConverter = new ConvertableConverter();
 }
コード例 #6
0
 /// <summary>
 /// Constructor 
 /// </summary>
 /// <param name="converter"></param>
 /// <param name="filter"></param>
 public ValueConverterConvention(IValueConverter converter, Func<DependencyProperty, PropertyInfo, bool> filter)
 {
     if (null == converter) throw new ArgumentNullException("converter");
     if (null == filter) throw new ArgumentNullException("filter");
     Converter = converter;
     Filter = filter;
 }
コード例 #7
0
 public ValueConversionStep( Type targetType, IValueConverter valueConverter )
 {
     Arg.NotNull( targetType, nameof( targetType ) );
     Arg.NotNull( valueConverter, nameof( valueConverter ) );
     this.targetType = targetType;
     converter = valueConverter;
 }
コード例 #8
0
		public CollectionSynchronizer(INotifyCollectionChanged source, ObservableCollection<object> target, IValueConverter valueConverter)
		{
			_source = source;
			_target = target;
			_valueConverter = valueConverter;
			_source.CollectionChanged += OnSourceCollectionChanged;
		}
コード例 #9
0
        public override View GetView(PropertyInfo property, object o, out BindableProperty targetProperty, out IValueConverter converter)
        {
            targetProperty = Label.TextProperty;
            converter = new ValueConverter();

            return new Label();
        }
コード例 #10
0
ファイル: GuiManager.cs プロジェクト: kukareka/printbox
 public string Prompt(string message, FlowDocument comment, IValueConverter converter, int length)
 {
     PromptDialog pd = new PromptDialog(App.Current.MainWindow, message, comment, converter, length);
     string r = (bool) ShowDialog(pd) ? pd.Keypad.Text : null;
     pd.Close();
     return r;
 }
コード例 #11
0
 public static BindingExpressionBase SetBinding(this FrameworkElement target, DependencyProperty dp, object source, string path, IValueConverter converter)
 {
     Binding b = new Binding(path);
     b.Source = source;
     b.Converter = converter;
     return BindingOperations.SetBinding(target, dp, b);
 }
コード例 #12
0
 public XmlTextSerializer(Type type, RedactAttribute redactAttribute, EncryptAttribute encryptAttribute, Type[] extraTypes)
 {
     _encryptAttribute = encryptAttribute;
     if (!ValueTypes.TryGetValueConverter(type, redactAttribute, extraTypes, out _valueConverter))
     {
         _valueConverter = SimpleTypeValueConverter.Create(type, redactAttribute);
     }
 }
コード例 #13
0
ファイル: ValueTypes.cs プロジェクト: JonOsment/XSerializer
 private static Func<bool, object, string> GetRedactFunc(IValueConverter valueConverter)
 {
     return
         (redactEnabled, value) =>
             redactEnabled
                 ? "XXXXXXXXXX"
                 : valueConverter.GetString(value, null);
 }
コード例 #14
0
 /// <summary>
 /// Sets a binding from code
 /// </summary>
 /// <param name="element"></param>
 /// <param name="property"></param>
 /// <param name="source"></param>
 /// <param name="path"></param>
 /// <param name="converter"></param>
 public static void SetBinding(FrameworkElement element, DependencyProperty property, object source, string path, IValueConverter converter = null)
 {
     Binding binding = new Binding();
     binding.Source = source;
     binding.Path = new PropertyPath(path);
     binding.Converter = converter;
     element.SetBinding(property, binding);
 }
コード例 #15
0
ファイル: CommandForMethod.cs プロジェクト: LenFon/Bifrost
 /// <summary>
 /// Initializes a new instance of <see cref="CommandForMethod"/>
 /// </summary>
 /// <param name="target">Target to bind to for the method, typically a ViewModel</param>
 /// <param name="methodName">Name of the method to bind to</param>
 /// <param name="canExecuteWhen">Optionally a reference to either a property or method that gets called to check if the command can execute</param>
 /// <param name="parameterConverter">Optionally a <see cref="IValueConverter"/> that will be used for converting value to the method</param>
 /// <remarks>
 /// The canExecuteWhen parameter can take the name of a property or a method. If it is 
 /// a property and the declaring type implements <see cref="INotifyPropertyChanged"/>,
 /// it will honor that and actually fire off the CanExecuteChanged if the property changes
 /// state. The property needs to be of type boolean, and a method can take one parameter,
 /// and the CommandParameter property from the view will be the content if so. The method
 /// needs to return a boolean.
 /// </remarks>
 public CommandForMethod(object target, string methodName, string canExecuteWhen = null, IValueConverter parameterConverter = null)
 {
     _target = target;
     _canExecuteWhen = canExecuteWhen;
     _parameterConverter = parameterConverter;
     GetMethod(target, methodName);
     if (!string.IsNullOrEmpty(canExecuteWhen)) SetupCanExecuteWhen(target, canExecuteWhen);
 }
コード例 #16
0
        public SimpleValueType(Type type, IValueConverter valueConverter)
            : base(type)
        {
            if (valueConverter == null)
                throw new ArgumentNullException("valueConverter");

            this.ValueConverter = valueConverter;
        }
コード例 #17
0
        public CustomBinding(string propertyName, object dataSource, string dataMember, IValueConverter valueConverter, object converterParameter = null)
            : base(propertyName, dataSource, dataMember)
        {
            if (valueConverter != null)
                this._converter = valueConverter;

            this._converterCulture = Thread.CurrentThread.CurrentUICulture;
            this._converterParameter = converterParameter;
        }
コード例 #18
0
        /// <summary>
        /// Creates a new <see cref="Binding"/> using <paramref name="bindingSource"/> as the <see cref="Binding.Source"/>,
        /// <paramref name="propertyPath"/> as the <see cref="Binding.Path"/>,
        /// and <paramref name="converter"/> as the <see cref="Binding.Converter"/>.
        /// </summary>
        /// <param name="bindingSource">The object to use as the new binding's <see cref="Binding.Source"/>.</param>
        /// <param name="propertyPath">The property path to use as the new binding's <see cref="Binding.Path"/>.</param>
        /// <param name="converter">The converter to use as the new binding's <see cref="Binding.Converter"/>.</param>
        /// <returns>A new <see cref="Binding"/> object.</returns>
        public static Binding CreateOneWayBinding(this INotifyPropertyChanged bindingSource, string propertyPath, IValueConverter converter) {
            Binding binding = new Binding();

            binding.Source = bindingSource;
            binding.Path = new PropertyPath(propertyPath);
            binding.Converter = converter;

            return binding;
        }
コード例 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultRunnableFactory"/> class.
 /// </summary>
 public DefaultRunnableFactory(IEnumerable<Type> availableRunnables, IValueConverter valueConverter = null, INameMatcher runnableNameMatcher = null, INameMatcher parameterNameMatcher = null,
                               IServiceFactory serviceFactory = null)
 {
     AvailableRunnables = availableRunnables ?? Enumerable.Empty<Type>();
     RunnableNameMatcher = runnableNameMatcher ?? new EqualityNameMatcher();
     ParameterNameMatcher = parameterNameMatcher ?? new EqualityNameMatcher();
     ValueConverter = valueConverter ?? new EmptyValueConverter();
     ServiceFactory = serviceFactory;
 }
コード例 #20
0
        public static BindingExpressionBase SetBinding(DependencyObject target, DependencyProperty targetProperty, DependencyObject source, DependencyProperty sourceProperty, BindingMode mode, IValueConverter converter)
        {
            Binding binding = new Binding(sourceProperty.Name);
            binding.Source = source;
            binding.Converter = converter;
            binding.Mode = mode;

            return BindingOperations.SetBinding(target, targetProperty, binding);
        }
コード例 #21
0
        internal static Binding Build(object source, string path, IValueConverter converter = null)
        {
            var binding = new Binding();
            binding.Source = source;
            binding.Path = new PropertyPath(path);
            binding.Converter = converter;

            return binding;
        }
コード例 #22
0
        public override View GetView(PropertyInfo property, object o, out BindableProperty targetProperty, out IValueConverter converter)
        {
            targetProperty = Editor.TextProperty;
            converter = new ValueConverter();

            return new Editor
            {
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
        }
コード例 #23
0
ファイル: IdMap.cs プロジェクト: andoco/mongodb-csharp
        /// <summary>
        /// Initializes a new instance of the <see cref="IdMap"/> class.
        /// </summary>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="memberGetter">The member getter.</param>
        /// <param name="memberSetter">The member setter.</param>
        /// <param name="valueType">Type of the value.</param>
        /// <param name="idGenerator">The id generator.</param>
        public IdMap(string memberName, Func<object, object> memberGetter, Action<object, object> memberSetter, IIdGenerator idGenerator, IValueConverter valueConverter, object unsavedValue)
            : base("_id", memberName, memberGetter, memberSetter, true)
        {
            if (idGenerator == null)
                throw new ArgumentNullException("idGenerator");

            this.IdGenerator = idGenerator;
            this.UnsavedValue = unsavedValue;
            this.ValueConverter = valueConverter;
        }
コード例 #24
0
 public BindingCreator(string path, FrameworkElement element, string canvasPath, string elementName,
                         DependencyProperty property, IValueConverter converter)
 {
     Path = path;
     Element = element;
     _canvasPath = canvasPath;
     Property = property;
     _converter = converter;
     ElementName = elementName;
 }
コード例 #25
0
        public XmlAttributeSerializer(Type type, string attributeName, RedactAttribute redactAttribute, EncryptAttribute encryptAttribute, IXmlSerializerOptions options)
        {
            _attributeName = attributeName;
            _encryptAttribute = encryptAttribute;

            if (!ValueTypes.TryGetValueConverter(type, redactAttribute, options.ExtraTypes, out _valueConverter))
            {
                _valueConverter = SimpleTypeValueConverter.Create(type, redactAttribute);
            }
        }
コード例 #26
0
        public ConverterBinding(IValueConverter valueConverter, Control control, Binding binding)
        {
            ValueConverter = valueConverter;
            Control = control;
            Binding = binding;

            Binding.Format += Convert;
            Binding.Parse += ConvertBack;
            Control.DataBindings.Add(Binding);
        }
コード例 #27
0
ファイル: OnOffUiProperty.cs プロジェクト: shamik94/sensus
        public override View GetView(PropertyInfo property, object o, out BindableProperty targetProperty, out IValueConverter converter)
        {            
            targetProperty = Switch.IsToggledProperty;
            converter = null;

            return new Switch
            {
                HorizontalOptions = LayoutOptions.Start
            };
        }
コード例 #28
0
        public override View GetView(PropertyInfo property, object o, out BindableProperty targetProperty, out IValueConverter converter)
        {
            targetProperty = Entry.TextProperty;
            converter = null;

            return new Entry
            {
                Keyboard = Keyboard.Default,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
        }
        public PropertyGroupDescription(string propertyName, IValueConverter converter,
		                                 StringComparison stringComparison)
        {
            if (converter == null)
                this.converter = new FakeConverter ();
            else
                this.converter = converter;

            this.propertyName = propertyName;
            this.stringComparison = stringComparison;
        }
コード例 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NestedClassValueType"/> class.
        /// </summary>
        /// <param name="nestedClassMap">The nested class map.</param>
        public NestedClassValueType(NestedClassMap nestedClassMap, IValueConverter valueConverter)
            : base(nestedClassMap.Type)
        {
            if (nestedClassMap == null)
                throw new ArgumentNullException("nestedClassMap");
            if (valueConverter == null)
                throw new ArgumentNullException("valueConverter");

            this.NestedClassMap = nestedClassMap;
            this.ValueConverter = valueConverter;
        }
コード例 #31
0
 protected virtual void DataBind(TextBlock lbl, string properyPath, IValueConverter converter)
 {
     databindUtil.DataBind(lbl, properyPath, converter, this.PropertyBag);
 }
コード例 #32
0
 protected virtual void DataBind(Image img, string properyPath, IValueConverter converter)
 {
     databindUtil.DataBind(img, properyPath, converter, this.propertyBag);
 }
コード例 #33
0
        private void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            if (args.NewValue == _currentSample)
            {
                return;
            }

            _currentSample = DataContext as Sample;

            RootPanel.Children.Clear();

            if (_currentSample != null)
            {
                var propertyDesc = _currentSample.PropertyDescriptor;

                if (propertyDesc == null)
                {
                    return;
                }

                foreach (var option in propertyDesc.Options)
                {
                    // Label
                    var label = new TextBlock
                    {
                        Text       = option.Label,
                        FontSize   = 15,
                        FontWeight = FontWeights.Bold
                    };
                    RootPanel.Children.Add(label);

                    // Control
                    Control            controlToAdd;
                    DependencyProperty dependencyProperty;
                    IValueConverter    converter = null;

                    IDictionary <string, object> propertyDict = propertyDesc.Expando;

                    switch (option.Kind)
                    {
                    case PropertyKind.Slider:
                    case PropertyKind.DoubleSlider:
                        var slider       = new Slider();
                        var sliderOption = option as SliderPropertyOptions;
                        if (sliderOption != null)
                        {
                            slider.Minimum       = sliderOption.MinValue;
                            slider.Maximum       = sliderOption.MaxValue;
                            slider.StepFrequency = sliderOption.Step;
                        }

                        if (option.Kind == PropertyKind.DoubleSlider)
                        {
                            slider.StepFrequency = 0.01;
                        }

                        if ((propertyDict[option.Name] as ValueHolder).Value is double value)
                        {
                            slider.Value = value;
                        }

                        controlToAdd       = slider;
                        dependencyProperty = RangeBase.ValueProperty;

                        break;

                    case PropertyKind.Enum:
                        var enumType = option.DefaultValue.GetType();
                        var comboBox = new ComboBox
                        {
                            ItemsSource  = Enum.GetNames(enumType),
                            SelectedItem = (propertyDict[option.Name] as ValueHolder).Value.ToString()
                        };

                        converter          = new EnumConverter(enumType);
                        controlToAdd       = comboBox;
                        dependencyProperty = Selector.SelectedItemProperty;
                        break;

                    case PropertyKind.Bool:
                        var checkBox = new ToggleSwitch();

                        if ((propertyDict[option.Name] as ValueHolder).Value is bool isOn)
                        {
                            checkBox.IsOn = isOn;
                        }

                        controlToAdd       = checkBox;
                        dependencyProperty = ToggleSwitch.IsOnProperty;
                        break;

                    case PropertyKind.Brush:
                        var colorComboBox = new ComboBox();
                        var dataSource    = typeof(Colors).GetTypeInfo().DeclaredProperties.Select(p => p.Name).ToList();
                        colorComboBox.ItemsSource = dataSource;

                        if ((propertyDict[option.Name] as ValueHolder).Value is SolidColorBrush brush &&
                            _colorNames.TryGetValue(brush.Color, out var color))
                        {
                            colorComboBox.SelectedIndex = dataSource.IndexOf(color);
                        }
                        else
                        {
                            colorComboBox.SelectedIndex = dataSource.IndexOf(option.DefaultValue.ToString());
                        }

                        converter = new SolidColorBrushConverter();

                        controlToAdd       = colorComboBox;
                        dependencyProperty = Selector.SelectedItemProperty;
                        break;
コード例 #34
0
        /// <summary>
        /// Создание двусторонней привязки к свойству
        /// </summary>
        /// <param name="entityProperty">Свойство</param>
        /// <param name="converter">Конвертер (при необходимости)</param>
        /// <returns>Объект типа <see cref="Binding"/></returns>
        private Binding CreateTwoWayBindingForProperty(SmartEntityProperty entityProperty, IValueConverter converter = null)
        {
            var binding = new Binding
            {
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = entityProperty,
                Path   = new PropertyPath("Value")
            };

            if (converter != null)
            {
                binding.Converter = converter;
            }

            return(binding);
        }
コード例 #35
0
        public override View GetView(PropertyInfo property, object o, out BindableProperty bindingProperty, out IValueConverter converter)
        {
            bindingProperty = DatePicker.DateProperty;
            converter       = null;

            return(new DatePicker
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                MinimumDate = DateTime.Now.Date
            });
        }
コード例 #36
0
ファイル: Chained.cs プロジェクト: vvvv/stride
 /// <summary>
 /// Initializes a new instance of the <see cref="Chained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="converter">The first value converter.</param>
 public Chained(IValueConverter converter)
     : this(converter, null, null, null, null, null, null, null)
 {
 }
コード例 #37
0
ファイル: RadHexView.cs プロジェクト: zach14c/UI-For-UWP
        private static void UpdateBinding(RadHexHubTile item, DependencyProperty property, string path, IValueConverter converter = null)
        {
            var bindingExpression = item.GetBindingExpression(property);

            if (!string.IsNullOrEmpty(path))
            {
                if (bindingExpression == null || bindingExpression.ParentBinding.Path.Path != path)
                {
                    item.SetBinding(property, new Binding {
                        Path = new PropertyPath(path), Converter = converter
                    });
                }
            }
            else if (bindingExpression != null)
            {
                item.ClearValue(property);
            }
        }
コード例 #38
0
 public LessThanEqualValidator(ValidationPipe pipe, IProxy argument, IErrorStringProvider errorProvider, IBoolProxy isEnforced,
                               IValueConverter valueConverter, bool strictValidation, bool validatesOnTargetUpdated)
     : base(pipe, argument, errorProvider, isEnforced, valueConverter, strictValidation, validatesOnTargetUpdated)
 {
 }
コード例 #39
0
        internal List <T> GetData <T>(ISheet sheet)
        {
            var result      = new List <T>();
            int rowIndex    = 0; //用于记录执行的位置,以便错误出现时提示
            int columnIndex = 0; //用于记录执行的位置,以便错误出现时提示

            if (sheet.PhysicalNumberOfRows > 0)
            {
                int limitEmptyRow = 5;                           // 最大允许5个连续空行(超出5行则不循环下面的数据了)
                int emptyRow      = 0;                           // 记录连续空行的个数
                T   t             = default(T);
                int start         = this.IsIgnoreHeader ? 1 : 0; // 表头的目录不需要,从1开始
                for (int i = start; i < sheet.PhysicalNumberOfRows; i++)
                {
                    rowIndex = i;//记录位置,以便提示错误
                    IRow row = sheet.GetRow(i);
                    // 行数
                    if (emptyRow >= limitEmptyRow)
                    {
                        break; // 最大允许连续空行
                    }
                    if (row == null || row.GetCell(0) == null || string.IsNullOrWhiteSpace(row.GetCell(0) + ""))
                    {
                        emptyRow++;
                        continue;
                    }
                    emptyRow = 0;//清空空行记录
                    t        = (T)Activator.CreateInstance(typeof(T));
                    // 开始赋值
                    foreach (PropertyInfo pi in this.PropertyInfos)
                    {
                        if (this.mapColumnIndex.ContainsKey(pi))
                        {
                            int index = this.mapColumnIndex[pi];
                            columnIndex = index;//记录位置,以便提示错误
                            try
                            {
                                // 读取Excel指定index列
                                string cellValue = row.GetCell(index) + "";
                                if (!string.IsNullOrWhiteSpace(cellValue))
                                {
                                    object objValue = null;
                                    if (this.mapValueConverter.ContainsKey(pi))
                                    {
                                        IValueConverter converter = this.mapValueConverter[pi];
                                        objValue = converter.deserialize(cellValue, pi.PropertyType, null);
                                    }
                                    else
                                    {
                                        objValue = this.changeType(cellValue, pi.PropertyType);
                                    }
                                    pi.SetValue(t, objValue);
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(string.Format("表:{0} -- 第{1}行,第{2}列错误,{3}", this.ClazzDisplayName, rowIndex + 1, columnIndex + 1, ex.Message));
                            }
                        }
                    }
                    result.Add(t);
                }
            }
            return(result);
        }
コード例 #40
0
ファイル: Binding.cs プロジェクト: jungh-yeon/TizenFX
        public static Binding Create <TSource>(Expression <Func <TSource, object> > propertyGetter, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null,
                                               string stringFormat = null)
        {
            if (propertyGetter == null)
            {
                throw new ArgumentNullException(nameof(propertyGetter));
            }

            return(new Binding(GetBindingPath(propertyGetter), mode, converter, converterParameter, stringFormat));
        }
コード例 #41
0
        private async void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            if (args.NewValue == _currentSample)
            {
                return;
            }

            _currentSample = DataContext as Sample;

            RootPanel.Children.Clear();

            if (_currentSample != null)
            {
                var propertyDesc = await _currentSample.GetPropertyDescriptorAsync();

                if (propertyDesc == null)
                {
                    return;
                }

                foreach (var option in propertyDesc.Options)
                {
                    // Label
                    var label = new TextBlock
                    {
                        Text       = option.Name + ":",
                        Foreground = new SolidColorBrush(Colors.Black)
                    };
                    RootPanel.Children.Add(label);

                    // Control
                    Control            controlToAdd;
                    DependencyProperty dependencyProperty;
                    IValueConverter    converter = null;

                    switch (option.Kind)
                    {
                    case PropertyKind.Slider:
                    case PropertyKind.DoubleSlider:
                        var slider       = new Slider();
                        var sliderOption = option as SliderPropertyOptions;
                        if (sliderOption != null)
                        {
                            slider.Minimum = sliderOption.MinValue;
                            slider.Maximum = sliderOption.MaxValue;
                        }

                        if (option.Kind == PropertyKind.DoubleSlider)
                        {
                            slider.StepFrequency = 0.01;
                        }

                        controlToAdd       = slider;
                        dependencyProperty = RangeBase.ValueProperty;

                        break;

                    case PropertyKind.Enum:
                        var enumType = option.DefaultValue.GetType();
                        var comboBox = new ComboBox
                        {
                            ItemsSource  = Enum.GetNames(enumType),
                            SelectedItem = option.DefaultValue.ToString()
                        };

                        converter          = new EnumConverter(enumType);
                        controlToAdd       = comboBox;
                        dependencyProperty = Selector.SelectedItemProperty;
                        break;

                    case PropertyKind.Bool:
                        var checkBox = new ToggleSwitch();

                        controlToAdd       = checkBox;
                        dependencyProperty = ToggleSwitch.IsOnProperty;
                        break;

                    case PropertyKind.Brush:
                        var colorComboBox = new ComboBox();
                        var dataSource    = typeof(Colors).GetTypeInfo().DeclaredProperties.Select(p => p.Name).ToList();
                        colorComboBox.ItemsSource   = dataSource;
                        colorComboBox.SelectedIndex = dataSource.IndexOf(option.DefaultValue.ToString());

                        converter = new SolidColorBrushConverter();

                        controlToAdd       = colorComboBox;
                        dependencyProperty = Selector.SelectedItemProperty;
                        break;

                    default:
                        var textBox = new TextBox {
                            Text = option.DefaultValue.ToString()
                        };

                        controlToAdd       = textBox;
                        dependencyProperty = TextBox.TextProperty;
                        break;
                    }

                    var binding = new Binding
                    {
                        Source    = propertyDesc.Expando,
                        Path      = new PropertyPath(option.Name + ".Value"),
                        Mode      = BindingMode.TwoWay,
                        Converter = converter
                    };

                    controlToAdd.SetBinding(dependencyProperty, binding);
                    controlToAdd.Margin = new Thickness(0, 5, 0, 20);
                    RootPanel.Children.Add(controlToAdd);
                }
            }
        }
コード例 #42
0
 public ParameterSetListConverter(IValueConverter <int> intConverter, IValueConverter <bool> boolConverter, int revision)
 {
     _revision      = revision;
     _intConverter  = intConverter;
     _boolConverter = boolConverter;
 }
コード例 #43
0
ファイル: Chained.cs プロジェクト: vvvv/stride
 /// <summary>
 /// Initializes a new instance of the <see cref="Chained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 public Chained(IValueConverter converter1, IValueConverter converter2, IValueConverter converter3)
     : this(converter1, converter2, converter3, null, null, null, null, null)
 {
 }
 public NamedPipeIpcServiceClient(IIpcMessageSerializer serializer, IValueConverter converter, string pipeName)
     : base(serializer, converter)
 {
     _pipeName = pipeName;
 }
コード例 #45
0
        public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null,
                                      string stringFormat = null)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }
            if (targetProperty == null)
            {
                throw new ArgumentNullException("targetProperty");
            }

            var binding = new Binding(path, mode, converter, stringFormat: stringFormat);

            self.SetBinding(targetProperty, binding);
        }
コード例 #46
0
 public BooleanConverter(IValueConverter innerConverter)
 {
     _innerConverter = innerConverter;
 }
コード例 #47
0
ファイル: Chained.cs プロジェクト: vvvv/stride
 /// <summary>
 /// Initializes a new instance of the <see cref="Chained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 /// <param name="converter4">The fourth value converter.</param>
 /// <param name="converter5">The fifth value converter.</param>
 /// <param name="converter6">The sixth value converter.</param>
 /// <param name="converter7">The seventh value converter.</param>
 /// <param name="converter8">The eighth value converter.</param>
 public Chained(IValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4, IValueConverter converter5, IValueConverter converter6, IValueConverter converter7, IValueConverter converter8)
 {
     Converter1 = converter1;
     Converter2 = converter2;
     Converter3 = converter3;
     Converter4 = converter4;
     Converter5 = converter5;
     Converter6 = converter6;
     Converter7 = converter7;
     Converter8 = converter8;
 }
コード例 #48
0
 public LocalizeEnumConverterTest()
 {
     _target = new LocalizeEnumConverter(_enumLocalizer);
 }
コード例 #49
0
 public BoltDataListConverter(IValueConverter <int> intConverter, IValueConverter <bool> boolConverter, IValueConverter <decimal> decimalConverter, int totalBolts)
 {
     _intConverter     = intConverter;
     _boolConverter    = boolConverter;
     _decimalConverter = decimalConverter;
     _totalBolts       = totalBolts;
 }
コード例 #50
0
 protected void DataBind(Slider slider, string properyPath, IValueConverter conv)
 {
     databindUtil.DataBind(slider, properyPath, conv, this.PropertyBag);
 }
コード例 #51
0
 protected void DataBind(FrameworkElement control, DependencyProperty dp, object source, string path,
                         IValueConverter converter)
 {
     databindUtil.DataBind(control, dp, source, path, converter);
 }
コード例 #52
0
 public ColorToBrush()
 {
     converter = new ColorToBrushConverter(); // system under test
 }
コード例 #53
0
        /// <summary>
        /// Creates a new <see cref="Binding"/> using <paramref name="bindingSource"/> as the <see cref="Binding.Source"/>,
        /// <paramref name="propertyPath"/> as the <see cref="Binding.Path"/>,
        /// and <paramref name="converter"/> as the <see cref="Binding.Converter"/>.
        /// </summary>
        /// <param name="bindingSource">The object to use as the new binding's <see cref="Binding.Source"/>.</param>
        /// <param name="propertyPath">The property path to use as the new binding's <see cref="Binding.Path"/>.</param>
        /// <param name="converter">The converter to use as the new binding's <see cref="Binding.Converter"/>.</param>
        /// <returns>A new <see cref="Binding"/> object.</returns>
        public static Binding CreateOneWayBinding(this INotifyPropertyChanged bindingSource, string propertyPath, IValueConverter converter)
        {
            Binding binding = new Binding();

            binding.Source    = bindingSource;
            binding.Path      = new PropertyPath(propertyPath);
            binding.Converter = converter;

            return(binding);
        }
コード例 #54
0
 public LightCommandListConverter(IValueConverter <int> intConverter)
 {
     _intConverter = intConverter;
 }
コード例 #55
0
ファイル: Fluent.cs プロジェクト: jeason0813/framework-2
 public static T Bind <T>(this T bindable, DependencyProperty property, object source, string sourcePath, IValueConverter converter) where T : DependencyObject
 {
     BindingOperations.SetBinding(bindable, property, new Binding(sourcePath)
     {
         Source = source, Converter = converter
     });
     return(bindable);
 }
コード例 #56
0
        public void SetBinding(string path, BindingMode vMode, UpdateSourceTrigger vTrigger, IValueConverter converter)
        {
            Binding b = new Binding(path);

            b.UpdateSourceTrigger = vTrigger;
            b.Mode      = vMode;
            b.Converter = converter;
            tBox.SetBinding(TextBox.TextProperty, b);
        }
コード例 #57
0
ファイル: Fluent.cs プロジェクト: jeason0813/framework-2
 public static T Bind <T, S>(this T bindable, DependencyProperty property, S source, Expression <Func <S, object> > sourcePath, IValueConverter converter) where T : DependencyObject
 {
     BindingOperations.SetBinding(bindable, property, new Binding(RouteVisitor.GetRoute(sourcePath))
     {
         Source = source, Converter = converter
     });
     return(bindable);
 }
コード例 #58
0
 public BindingSource <TNewSource, TTarget> AddBinding <TNewSource>(TNewSource source, Expression <Func <TNewSource, object> > sourceProperty, Expression <Func <TTarget, object> > targetProperty, IValueConverter converter)
     where TNewSource : class, INotifyPropertyChanged
 {
     return(myControler.AddBinding(source, sourceProperty, targetProperty, converter));
 }
コード例 #59
0
 public void Add(IValueConverter converter) => _converters.Insert(0, converter);
コード例 #60
0
ファイル: Chained.cs プロジェクト: vvvv/stride
 /// <summary>
 /// Initializes a new instance of the <see cref="Chained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 /// <param name="converter4">The fourth value converter.</param>
 /// <param name="converter5">The fifth value converter.</param>
 /// <param name="converter6">The sixth value converter.</param>
 public Chained(IValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4, IValueConverter converter5, IValueConverter converter6)
     : this(converter1, converter2, converter3, converter4, converter5, converter6, null, null)
 {
 }