Example #1
0
 public Bind <TBinding> WithLoading <TControl>(TControl topControl, ProgressBar progressBar, Expression <Func <TBinding, bool> > member)
     where TControl : Control
 {
     For(progressBar, _ => _.Visible, member);
     topControl.AddInverseBinding(nameof(topControl.Enabled), _item, ReflectionUtils.GetPropertyName(member));
     return(this);
 }
Example #2
0
        public Bind <TBinding> For <TControl, TProperty>(TControl control, Expression <Func <TControl, TProperty> > controlProperty, Expression <Func <TBinding, TProperty> > member, Func <TBinding, BindableObject> dependsOn)
            where TControl : Control
        {
            var binding = control.DataBindings.Add(ReflectionUtils.GetPropertyName(controlProperty), _item, ReflectionUtils.GetPropertyName(member));

            dependsOn(_item).PropertyChanged += (sender, args) => binding.ReadValue();
            return(this);
        }
        public Bind <TBinding> WithConverter <TSource>(
            Expression <Func <TBinding, TSource> > member,
            SourceToControlConverter <TSource, TProperty> converter)
        {
            var propertyName = ReflectionUtils.GetPropertyName(_controlProperty);
            var dataMember   = ReflectionUtils.GetFullPath(member);
            var binding      = new ConversionBinding <TSource, TProperty>(propertyName, _item, dataMember, converter);

            _control.DataBindings.Add(binding);
            return(this);
        }
Example #4
0
 public Bind <TBinding> For <TProperty, TDisplayProperty, TValueProperty>(
     ComboBox comboBox,
     Func <TBinding, BindingList <TProperty> > member,
     Expression <Func <TProperty, TDisplayProperty> > displayMember,
     Expression <Func <TProperty, TValueProperty> > valueMember)
 {
     comboBox.DataSource    = member(_item);
     comboBox.DisplayMember = ReflectionUtils.GetPropertyName(displayMember);
     comboBox.ValueMember   = ReflectionUtils.GetPropertyName(valueMember);
     return(this);
 }
 private static void BindSelectedItem <TBinding, TSource, TProperty>(ComboBox comboBox,
                                                                     TBinding item,
                                                                     Expression <Func <TBinding, TProperty> > member,
                                                                     ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     comboBox.DataBindings.Add(nameof(ComboBox.SelectedItem), item, ReflectionUtils.GetPropertyName(member));
     comboBox.SetDefault(binding.DefaultValue);
     comboBox.SelectionChangeCommitted += (sender, e) => comboBox.DataBindings[nameof(ComboBox.SelectedItem)].WriteValue();
     (comboBox.DataSource as IBindingList).ListChanged += (sender, e) =>
     {
         var value = ReflectionUtils.GetValue(item, member);
         if (value == null)
         {
             comboBox.SetDefault(binding.DefaultValue);
         }
     };
 }
 public ComboBoxBinding <TSource> Value <TValueProperty>(Expression <Func <TSource, TValueProperty> > valueMember)
 {
     ValueMember = ReflectionUtils.GetPropertyName(valueMember);
     return(this);
 }
 public ComboBoxBinding <TSource> Display <TDisplayProperty>(Expression <Func <TSource, TDisplayProperty> > displayMember)
 {
     DisplayMember = ReflectionUtils.GetPropertyName(displayMember);
     return(this);
 }
Example #8
0
 /// <summary>
 /// Binds <see cref="TextBox.Text"/> of <paramref name="textBox"/> to <paramref name="member"/>
 /// </summary>
 /// <param name="textBox"></param>
 /// <param name="member"></param>
 /// <returns></returns>
 public Bind <TBinding> For(TextBox textBox, Expression <Func <TBinding, string> > member)
 {
     textBox.AddBinding(_item, ReflectionUtils.GetPropertyName(member));
     return(this);
 }
Example #9
0
 public Bind <TBinding> For <TControl, TProperty>(TControl control, Expression <Func <TControl, TProperty> > controlProperty, Expression <Func <TBinding, TProperty> > member)
     where TControl : Control
 {
     control.DataBindings.Add(ReflectionUtils.GetPropertyName(controlProperty), _item, ReflectionUtils.GetFullPath(member));
     return(this);
 }