コード例 #1
0
		public void SetBinding (DependencyProperty dp, Binding binding) {
			if (dp == null || binding == null)
				throw new ArgumentNullException ();

			if (!bindings.Contains (binding))
				bindings.Add (binding);

			binding.AddTargetProperty (this, dp);
			binding.SourceUpdated +=
                (s, e) => {
				var bind = (Binding)s;
				if (bind.Mode != BindingMode.OneWayToSource) {
					if ( bind.IsBound ( ) ) {
						var value = bind.GetSourceValue ();
						foreach (var prop in bind.GetTargetProperties(this)) {
							this.SetValue (prop, value);
						}
					}
				}
			};

			if (binding.Source == null)
				binding.DataContext = this.DataContext;

			binding.OnSourceUpdated ();
		}