private static void AddSimpleTypedBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Simple TypedBinding var binding = new TypedBinding <Customer, Customer>(customer1, c => c.Gender, customer2, c => c.Gender); bindingManager.Bindings.Add(binding); #endregion }
public void TypedBindingConstructor() { tlog.Debug(tag, $"TypedBindingConstructor START"); Func <View, FocusEffect> getter = (v) => new FocusEffect(); var mt = new TypedBinding <View, FocusEffect>(getter, null, null); Assert.IsNotNull(mt, "null TypedBinding"); Assert.IsInstanceOf <TypedBinding <View, FocusEffect> >(mt, "Should return TypedBinding instance."); tlog.Debug(tag, $"TypedBindingConstructor END"); }
private static void AddComplexTypedBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Complex TypedBinding var binding = new TypedBinding <Customer, Customer>(customer1, c => c.Address.Line2, customer2, c => c.Address.Line2); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new FormerAddressLineConverter(); bindingManager.Bindings.Add(binding); #endregion }
internal static void Tests() { var person = new Person(); Console.WriteLine("Name: " + person.Name + "..."); Console.WriteLine("Age: " + person.Age); Console.WriteLine("Gender: " + person.Gender); var person1 = new Person { Name = "John", Age = 1 }; var person2 = new Person { Name = "Jack", Age = 2 }; var manager1 = new BindingManager(); var binding1 = new TypedBinding <Person, Person>(); binding1.SourceObject = person1; binding1.SourceExpression = s => s.Age; binding1.TargetObject = person2; binding1.TargetExpression = t => t.Age; manager1.Bindings.Add(binding1); person1.Age = 69; Console.WriteLine("Person1: " + person1.Age); Console.WriteLine("Person2: " + person2.Age + " (Expect 69)"); person2.Age = 18; Console.WriteLine("Person2: " + person2.Age); Console.WriteLine("Person1: " + person1.Age + " (Expect 18)"); var manager2 = new BindingManager(); manager2.Bindings.Add(new TypedBinding <Person, Person>(person2, t => t.Name, person1, s => s.Name)); person1.Name = "Mary"; Console.WriteLine("Person1: " + person1.Name); Console.WriteLine("Person2: " + person2.Name + " (Expect Mary)"); person2.Name = "Lucene"; Console.WriteLine("Person2: " + person2.Name); Console.WriteLine("Person1: " + person1.Name + " (Expect Lucene)"); person1.Name = null; Console.WriteLine("Person1: " + (person1.Name == null ? "null" : person1.Name)); Console.WriteLine("Person2: " + (person2.Name == null ? "null" : person2.Name)); person2.Name = null; Console.WriteLine("Person2: " + (person2.Name == null ? "null" : person2.Name)); Console.WriteLine("Person1: " + (person1.Name == null ? "null" : person1.Name)); }
public void ApplyCoreTest() { tlog.Debug(tag, $"ApplyCoreTest START"); try { Func <View, FocusEffect> getter = (v) => new FocusEffect(); var mt = new TypedBinding <View, FocusEffect>(getter, null, null); Assert.IsNotNull(mt, "null TypedBinding"); mt.ApplyCore(new View(), new View(), View.FocusableProperty); } catch (Exception e) { Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"ApplyCoreTest END"); }
public void UnapplyTest() { tlog.Debug(tag, $"UnapplyTest START"); try { Func <View, FocusEffect> getter = (v) => new FocusEffect(); var mt = new TypedBinding <View, FocusEffect>(getter, null, null); Assert.IsNotNull(mt, "null TypedBinding"); mt.Unapply(); } catch (Exception e) { Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"UnapplyTest END"); }
public void ApplyTest() { tlog.Debug(tag, $"ApplyTest START"); try { Func <View, FocusEffect> getter = (v) => new FocusEffect(); var mt = new TypedBinding <View, FocusEffect>(getter, null, null); Assert.IsNotNull(mt, "null TypedBinding"); mt.Apply(); } catch (InvalidOperationException e) { Assert.True(true, "Caught Exception" + e.ToString()); } tlog.Debug(tag, $"ApplyTest END"); }
internal MvvmFxTester(INumberName subjectUnderTest) { _subjectUnderTest = subjectUnderTest; var guineaPig = new TargetObject(); // bind using (var bindingManager = new BindingManager()) { var numberBinding = new TypedBinding<INumberName, INumberName> (guineaPig, t => t.Number, _subjectUnderTest, s => s.Number); var nameBinding = new TypedBinding<INumberName, INumberName> (guineaPig, t => t.FullName, _subjectUnderTest, s => s.FullName); bindingManager.Bindings.Add(numberBinding); bindingManager.Bindings.Add(nameBinding); var testDuration = new Stopwatch(); testDuration.Start(); Run(); testDuration.Stop(); Console.WriteLine( string.Format("Bind to source {0}: {1} msec.", subjectUnderTest.GetType().Name, testDuration.ElapsedMilliseconds.ToString("#,###"))); // unbind bindingManager.Bindings.Remove(numberBinding); bindingManager.Bindings.Remove(nameBinding); //bind back numberBinding = new TypedBinding<INumberName, INumberName> (_subjectUnderTest, t => t.Number, guineaPig, s => s.Number); nameBinding = new TypedBinding<INumberName, INumberName> (_subjectUnderTest, t => t.FullName, guineaPig, s => s.FullName); bindingManager.Bindings.Add(numberBinding); bindingManager.Bindings.Add(nameBinding); testDuration.Restart(); Run(); testDuration.Stop(); Console.WriteLine( string.Format("Bind to target {0}: {1} msec.", guineaPig.GetType().Name, testDuration.ElapsedMilliseconds.ToString("#,###"))); Console.WriteLine(); } }
internal MvvmFxTester(INumberName subjectUnderTest) { _subjectUnderTest = subjectUnderTest; var guineaPig = new TargetObject(); // bind using (var bindingManager = new BindingManager()) { var numberBinding = new TypedBinding <INumberName, INumberName> (guineaPig, t => t.Number, _subjectUnderTest, s => s.Number); var nameBinding = new TypedBinding <INumberName, INumberName> (guineaPig, t => t.FullName, _subjectUnderTest, s => s.FullName); bindingManager.Bindings.Add(numberBinding); bindingManager.Bindings.Add(nameBinding); var testDuration = new Stopwatch(); testDuration.Start(); Run(); testDuration.Stop(); Console.WriteLine( string.Format("Bind to source {0}: {1} msec.", subjectUnderTest.GetType().Name, testDuration.ElapsedMilliseconds.ToString("#,###"))); // unbind bindingManager.Bindings.Remove(numberBinding); bindingManager.Bindings.Remove(nameBinding); //bind back numberBinding = new TypedBinding <INumberName, INumberName> (_subjectUnderTest, t => t.Number, guineaPig, s => s.Number); nameBinding = new TypedBinding <INumberName, INumberName> (_subjectUnderTest, t => t.FullName, guineaPig, s => s.FullName); bindingManager.Bindings.Add(numberBinding); bindingManager.Bindings.Add(nameBinding); testDuration.Restart(); Run(); testDuration.Stop(); Console.WriteLine( string.Format("Bind to target {0}: {1} msec.", guineaPig.GetType().Name, testDuration.ElapsedMilliseconds.ToString("#,###"))); Console.WriteLine(); } }
public void GetTargetValueTest() { tlog.Debug(tag, $"GetTargetValueTest START"); try { Func <View, FocusEffect> getter = (v) => new FocusEffect(); var mt = new TypedBinding <View, FocusEffect>(getter, null, null); Assert.IsNotNull(mt, "null TypedBinding"); var ret = mt.GetTargetValue(new View(), typeof(bool)); Assert.IsNotNull(mt, "null TypedBinding"); } catch (Exception e) { Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"GetTargetValueTest END"); }
internal static void Tests() { var person = new Person(); Console.WriteLine("Name: " + person.Name + "..."); Console.WriteLine("Age: " + person.Age); Console.WriteLine("Gender: " + person.Gender); var person1 = new Person { Name = "John", Age = 1 }; var person2 = new Person { Name = "Jack", Age = 2 }; var manager1 = new BindingManager(); var binding1 = new TypedBinding<Person, Person>(); binding1.SourceObject = person1; binding1.SourceExpression = s => s.Age; binding1.TargetObject = person2; binding1.TargetExpression = t => t.Age; manager1.Bindings.Add(binding1); person1.Age = 69; Console.WriteLine("Person1: " + person1.Age); Console.WriteLine("Person2: " + person2.Age + " (Expect 69)"); person2.Age = 18; Console.WriteLine("Person2: " + person2.Age); Console.WriteLine("Person1: " + person1.Age + " (Expect 18)"); var manager2 = new BindingManager(); manager2.Bindings.Add(new TypedBinding<Person, Person>(person2, t => t.Name, person1, s => s.Name)); person1.Name = "Mary"; Console.WriteLine("Person1: " + person1.Name); Console.WriteLine("Person2: " + person2.Name + " (Expect Mary)"); person2.Name = "Lucene"; Console.WriteLine("Person2: " + person2.Name); Console.WriteLine("Person1: " + person1.Name + " (Expect Lucene)"); person1.Name = null; Console.WriteLine("Person1: " + (person1.Name == null ? "null" : person1.Name)); Console.WriteLine("Person2: " + (person2.Name == null ? "null" : person2.Name)); person2.Name = null; Console.WriteLine("Person2: " + (person2.Name == null ? "null" : person2.Name)); Console.WriteLine("Person1: " + (person1.Name == null ? "null" : person1.Name)); }
private void AddBindings() { _customer = new Customer(); _bindingManager = new BindingManager(); _bindingManager.BindOnValidation = true; _bindingManager.Bindings.Add( new TypedBinding <TextBox, Customer>(CustomerNameUI, t => t.Text, _customer, s => s.Name)); _bindingManager.Bindings.Add( new TypedBinding <Label, Customer>(CustomerNameBO, t => t.Text, _customer, s => s.Name)); var address = _customer.Address; _bindingManager.Bindings.Add( new TypedBinding <TextBox, Address>(CustomerAddressCountryUI, t => t.Text, address, s => s.Country)); _bindingManager.Bindings.Add( new TypedBinding <Label, Address>(CustomerAddressCountryBO, t => t.Text, address, s => s.Country)); _bindingManager.Bindings.Add( new TypedBinding <TextBox, Customer>(CustomerAddressZipCodeUI, t => t.Text, _customer, s => s.Address.ZipCode)); _bindingManager.Bindings.Add( new TypedBinding <Label, Customer>(CustomerAddressZipCodeBO, t => t.Text, _customer, s => s.Address.ZipCode)); var invoice = _customer.Invoice; _bindingManager.Bindings.Add( new TypedBinding <TextBox, Invoice>(CustomerInvoiceInvoiceNumberUI, t => t.Text, invoice, s => s.InvoiceNumber)); _bindingManager.Bindings.Add( new TypedBinding <Label, Invoice>(CustomerInvoiceInvoiceNumberBO, t => t.Text, invoice, s => s.InvoiceNumber)); var invoicedateBinding = new TypedBinding <TextBox, Customer>(CustomerInvoiceInvoiceDateUI, t => t.Text, _customer, s => s.Invoice.InvoiceDate); invoicedateBinding.Converter = new DateTimeToDateConverter(); invoicedateBinding.ConverterCulture = CultureInfo.CurrentCulture; _bindingManager.Bindings.Add(invoicedateBinding); _bindingManager.Bindings.Add(new TypedBinding <Label, Customer> { TargetObject = CustomerInvoiceInvoiceDateBO, TargetExpression = t => t.Text, SourceObject = _customer, SourceExpression = s => s.Invoice.InvoiceDate, Converter = new DateTimeToDateConverter(), ConverterCulture = CultureInfo.CurrentCulture }); }
private void AddBindings() { _customer = new Customer(); _bindingManager = new BindingManager(); _bindingManager.BindOnValidation = true; _bindingManager.Bindings.Add( new TypedBinding<TextBox, Customer>(CustomerNameUI, t => t.Text, _customer, s => s.Name)); _bindingManager.Bindings.Add( new TypedBinding<Label, Customer>(CustomerNameBO, t => t.Text, _customer, s => s.Name)); var address = _customer.Address; _bindingManager.Bindings.Add( new TypedBinding<TextBox, Address>(CustomerAddressCountryUI, t => t.Text, address, s => s.Country)); _bindingManager.Bindings.Add( new TypedBinding<Label, Address>(CustomerAddressCountryBO, t => t.Text, address, s => s.Country)); _bindingManager.Bindings.Add( new TypedBinding<TextBox, Customer>(CustomerAddressZipCodeUI, t => t.Text, _customer, s => s.Address.ZipCode)); _bindingManager.Bindings.Add( new TypedBinding<Label, Customer>(CustomerAddressZipCodeBO, t => t.Text, _customer, s => s.Address.ZipCode)); var invoice = _customer.Invoice; _bindingManager.Bindings.Add( new TypedBinding<TextBox, Invoice>(CustomerInvoiceInvoiceNumberUI, t => t.Text, invoice, s => s.InvoiceNumber)); _bindingManager.Bindings.Add( new TypedBinding<Label, Invoice>(CustomerInvoiceInvoiceNumberBO, t => t.Text, invoice, s => s.InvoiceNumber)); var invoicedateBinding = new TypedBinding<TextBox, Customer>(CustomerInvoiceInvoiceDateUI, t => t.Text, _customer, s => s.Invoice.InvoiceDate); invoicedateBinding.Converter = new DateTimeToDateConverter(); invoicedateBinding.ConverterCulture = CultureInfo.CurrentCulture; _bindingManager.Bindings.Add(invoicedateBinding); _bindingManager.Bindings.Add(new TypedBinding<Label, Customer> { TargetObject = CustomerInvoiceInvoiceDateBO, TargetExpression = t => t.Text, SourceObject = _customer, SourceExpression = s => s.Invoice.InvoiceDate, Converter = new DateTimeToDateConverter(), ConverterCulture = CultureInfo.CurrentCulture }); }
private static void AddSimpleTypedBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Simple TypedBinding var binding = new TypedBinding<Customer, Customer>(customer1, c => c.Gender, customer2, c => c.Gender); bindingManager.Bindings.Add(binding); #endregion }
private static void AddComplexTypedBinding(Customer customer1, Customer customer2, BindingManager bindingManager) { #region Complex TypedBinding var binding = new TypedBinding<Customer, Customer>(customer1, c => c.Address.Line2, customer2, c => c.Address.Line2); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new FormerAddressLineConverter(); bindingManager.Bindings.Add(binding); #endregion }