예제 #1
0
        static void Bind_Poco_TwoWay()
        {
            // Binding Source (Any object).
            var person = new Person0 {
                Id = 123, Name = "Taro"
            };

            // Binding Target (DependencyObject).
            var textBox = new TextBox {
                Text = "Default"
            };

            Console.WriteLine(textBox.Text);

            // Binds target to source.
            var binding = new Binding(nameof(person.Name))
            {
                Source = person, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };

            textBox.SetBinding(TextBox.TextProperty, binding);
            Console.WriteLine(textBox.Text);

            // Changes source value.
            // Notification does not work in usual property setting.
            //person.Name = "Jiro";
            var properties = TypeDescriptor.GetProperties(person);

            properties[nameof(person.Name)].SetValue(person, "Jiro");
            Console.WriteLine(textBox.Text);

            // Changes target value.
            textBox.Text = "Saburo";
            Console.WriteLine(person.Name);
        }
예제 #2
0
        static void Bind_Poco_TwoWay()
        {
            // Binding Source (Any object).
            var person = new Person0 { Id = 123, Name = "Taro" };

            // Binding Target (DependencyObject).
            var textBox = new TextBox { Text = "Default" };
            Console.WriteLine(textBox.Text);

            // Binds target to source.
            var binding = new Binding(nameof(person.Name)) { Source = person, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged };
            textBox.SetBinding(TextBox.TextProperty, binding);
            Console.WriteLine(textBox.Text);

            // Changes source value.
            // Notification does not work in usual property setting.
            //person.Name = "Jiro";
            var properties = TypeDescriptor.GetProperties(person);
            properties[nameof(person.Name)].SetValue(person, "Jiro");
            Console.WriteLine(textBox.Text);

            // Changes target value.
            textBox.Text = "Saburo";
            Console.WriteLine(person.Name);
        }
예제 #3
0
        static void PropertyDescriptor_AddValueChanged()
        {
            var person = new Person0 {
                Id = 123, Name = "Taro"
            };
            var properties = TypeDescriptor.GetProperties(person);
            var nameProp   = properties[nameof(person.Name)];

            nameProp.AddValueChanged(person, (o, e) => Console.WriteLine(person.Name));
            nameProp.SetValue(person, "Jiro");
        }
예제 #4
0
 static void PropertyDescriptor_AddValueChanged()
 {
     var person = new Person0 { Id = 123, Name = "Taro" };
     var properties = TypeDescriptor.GetProperties(person);
     var nameProp = properties[nameof(person.Name)];
     nameProp.AddValueChanged(person, (o, e) => Console.WriteLine(person.Name));
     nameProp.SetValue(person, "Jiro");
 }