コード例 #1
0
 public static void Bind <TBinding, TSource, TProperty>(
     this ComboBox comboBox,
     TBinding item,
     Expression <Func <TBinding, TProperty> > member, ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     BindSource(comboBox, binding);
     BindSelectedItem(comboBox, item, member, binding);
 }
コード例 #2
0
ファイル: Bind.cs プロジェクト: abravodev/winforms-mvvm
 public Bind <TBinding> For <TSource, TProperty>(
     ComboBox comboBox,
     Expression <Func <TBinding, TProperty> > member,
     ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     comboBox.Bind(_item, member, binding);
     return(this);
 }
コード例 #3
0
 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);
         }
     };
 }
コード例 #4
0
 private static void BindSource <TSource>(ComboBox comboBox, ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     comboBox.DataSource    = binding.Source;
     comboBox.DisplayMember = binding.DisplayMember;
     comboBox.ValueMember   = binding.ValueMember;
 }