Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: C# | Size: 0.98 KB | Hits: 28 | Expires: Never
Copy text to clipboard
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Data;
  4.  
  5. namespace dp_test
  6. {
  7.         class A : DependencyObject
  8.         {
  9.                 public int Val
  10.                 {
  11.                         get { return (int)GetValue(ValProperty); }
  12.                         set { SetValue(ValProperty, value); }
  13.                 }
  14.  
  15.                 public static readonly DependencyProperty ValProperty =
  16.                         DependencyProperty.Register("Val", typeof(int), typeof(A), null);
  17.  
  18.  
  19.         }
  20.  
  21.         class B : DependencyObject
  22.         {
  23.                 public int Val
  24.                 {
  25.                         get { return (int)GetValue(ValProperty); }
  26.                         set { SetValue(ValProperty, value); }
  27.                 }
  28.  
  29.                 public static readonly DependencyProperty ValProperty =
  30.                         DependencyProperty.Register("Val", typeof(int), typeof(B), null);
  31.         }
  32.  
  33.         class Program
  34.         {
  35.                 static void Main(string[] args)
  36.                 {
  37.                         A aaa = new A();
  38.                         B bbb = new B();
  39.  
  40.                         Binding binding = new Binding("Val");
  41.                         binding.Source = bbb;
  42.  
  43.                         BindingOperations.SetBinding(aaa, A.ValProperty, binding);
  44.  
  45.                         bbb.Val = 7;
  46.  
  47.                         Console.WriteLine("A = " + aaa.Val + ", B = " + bbb.Val);
  48.                 }
  49.         }
  50. }