Esempio n. 1
0
        public void Breaking_The_Chain_Should_Assign_Default_Value_To_Target_If_Specified()
        {
            ResetBinding();
            LambdaBinding.BindOneWay(() => Student.School.Address.City, () => schoolCity, "[No City]");

            Student.School = null;
            Assert.AreEqual("[No City]", schoolCity);
        }
Esempio n. 2
0
 /// <summary>
 /// Clears the <see cref="Binding"/> property.
 /// </summary>
 protected void ResetBinding()
 {
     if (Binding != null)
     {
         Binding.Dispose();
     }
     Binding = null;
 }
Esempio n. 3
0
        public void One_Way_Binding_Should_Use_Converter_If_Specified()
        {
            Student student  = new Student();
            int     intValue = 0;

            LambdaBinding.BindOneWay(() => student.Name, () => intValue, name => int.Parse(name));

            student.Name = "451";
            Assert.AreEqual(451, intValue);
        }
Esempio n. 4
0
 private void bind(PropertyItem propertyItem, RadioButton btnTopLeft, Anchor anchor)
 {
     BindingOperations.SetBinding(btnTopLeft, ToggleButton.IsCheckedProperty, LambdaBinding.New(
                                      new Binding("Value")
     {
         Source = propertyItem, Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay
     },
                                      (object source) => { return((Anchor)source == anchor); },
                                      (bool source) => { return(source ? anchor : Binding.DoNothing); }
                                      ));
 }
 public FrameworkElement ResolveEditor(PropertyItem propertyItem)
 {
     BindingOperations.SetBinding(ctCombo, ComboBox.SelectedItemProperty, LambdaBinding.New(
                                      new Binding("Value")
     {
         Source = propertyItem, Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay
     },
                                      (ExtraPropertyId source) => { return(App.DataSources.FirstOrDefault(d => d.PropertyId.Equals(source))); },
                                      (DataSourceInfo source) => { return(source == null ? null : source.PropertyId); }
                                      ));
     return(this);
 }
Esempio n. 6
0
        public void Updates_Should_Work_Both_Ways()
        {
            var binding = LambdaBinding.BindTwoWay(
                () => FirstStudent.Name,
                () => SecondStudent.Name);

            FirstStudent.Name = "Peter";
            Assert.AreEqual("Peter", SecondStudent.Name);

            SecondStudent.Name = "Parker";
            Assert.AreEqual("Parker", FirstStudent.Name);
        }
Esempio n. 7
0
 public FrameworkElement ResolveEditor(PropertyItem propertyItem)
 {
     BindingOperations.SetBinding(textbox, TextBox.TextProperty, LambdaBinding.New(
                                      new Binding("Value")
     {
         Source = propertyItem, Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay
     },
                                      (Filename source) => { return((string)source); },
                                      (string source) => { return((Filename)source); }
                                      ));
     _expression = textbox.GetBindingExpression(TextBox.TextProperty);
     return(this);
 }
Esempio n. 8
0
        public void Two_Way_Value_Conversion_Should_Be_Applied()
        {
            var binding = LambdaBinding.BindTwoWay(
                () => FirstStudent.Age,
                () => SecondStudent.Name,
                i => i.ToString(),
                n => int.Parse(n));

            FirstStudent.Age = 25;
            Assert.AreEqual("25", SecondStudent.Name);

            SecondStudent.Name = "30";
            Assert.AreEqual(30, FirstStudent.Age);
        }
Esempio n. 9
0
        public IBinding BindOneWay <TSource, TTarget>
        (
            Expression <Func <TSource> > source,
            Expression <Func <TTarget> > target,
            Func <TSource, TTarget> converter = null,
            TTarget defaultValue = default(TTarget)
        )
        {
            var key     = new BindingKey(target.MemberInfo());
            var binding = new LambdaBindingProxy(LambdaBinding.BindOneWay(source, target, converter, defaultValue));

            if (!Bindings.Value.TryAdd(key, binding))
            {
                binding.Dispose();
                throw new InvalidOperationException(string.Format("Свойство {0} уже подписано на обновления", key.Name));
            }

            return(binding);
        }
        public static IEnumerable <TItem> ShowCheckList <TItem>(Window owner, IEnumerable <CheckListItem <TItem> > items, string prompt, string okButton, string[] columnTitles, string promptSure = null)
        {
            var wnd = new CheckListWindow()
            {
                Owner = owner
            };

            wnd.ctPrompt.Text    = prompt;
            wnd.ctOkBtn.Text     = okButton;
            wnd.ctCancelBtn.Text = App.Translation.Prompt.Cancel;
            for (int i = 0; i < columnTitles.Length; i++)
            {
                wnd.ctGrid.Columns[i + 1].Header     = columnTitles[i];
                wnd.ctGrid.Columns[i + 1].Visibility = Visibility.Visible;
                if (i != columnTitles.Length - 1) // mark all columns except for the last one as auto width
                {
                    wnd.ctGrid.Columns[i + 1].Width = DataGridLength.Auto;
                }
            }
            wnd._promptSure    = promptSure;
            wnd._promptSureYes = okButton.Replace('_', '&');

            wnd._checkItems        = new ObservableCollection <CheckListItem>(items);
            wnd.ctGrid.ItemsSource = wnd._checkItems;

            BindingOperations.SetBinding(wnd.chkSelectAll, CheckBox.IsCheckedProperty, LambdaBinding.New(
                                             new Binding {
                Source = wnd._checkAll, Path = new PropertyPath("Value")
            },
                                             (bool?checkAll) => checkAll,
                                             (bool?checkAll) => { wnd.setAllCheckboxes(checkAll); return(checkAll); }
                                             ));

            if (wnd.ShowDialog() != true)
            {
                return(Enumerable.Empty <TItem>());
            }

            return(wnd._checkItems.OfType <CheckListItem <TItem> >().Where(cli => cli.IsChecked).Select(cli => cli.Item));
        }
Esempio n. 11
0
 public LambdaBindingProxy(LambdaBinding binding)
 {
     Contract.Requires <ArgumentNullException>(binding != null);
     _binding = binding;
 }
Esempio n. 12
0
 /// <summary>
 /// Inits the <see cref="Binding"/> property. The default implementation
 /// registers a binding that updates the student's <see cref="Student.SchoolCity"/>
 /// with the <see cref="Address.City"/> of the student's school's address.
 /// </summary>
 protected virtual void CreateBinding()
 {
     Binding = LambdaBinding.BindOneWay(() => Student.School.Address.City, () => Student.SchoolCity);
 }
Esempio n. 13
0
 /// <summary>
 /// Inits the <see cref="Binding"/> property. The default implementation
 /// registers a binding that updates the student's <see cref="Student.SchoolCity"/>
 /// with the <see cref="Address.City"/> of the student's school's address.
 /// </summary>
 protected virtual void CreateBinding()
 {
     Binding = LambdaBinding.BindOneWay(() => Student.School.Address.City, () => Student.SchoolCity);
 }
Esempio n. 14
0
 /// <summary>
 /// Clears the <see cref="Binding"/> property.
 /// </summary>
 protected void ResetBinding()
 {
     if (Binding != null)
       {
     Binding.Dispose();
       }
       Binding = null;
 }