XAML과 마찬가지로 C#의 종속성 속성에 바인딩하는 방법이 있습니까?코드에서 종속성 속성에 바인딩 (변경 알림 외)
내가 변경 알림을 할 수 있다는 것을 알고 있지만 "양방향"바인딩을 수행 할 수있는 방법이 필요했습니다. (내 값을 변경하면 종속성 속성을 변경하도록.)
예 :
내보기 모델에서public static readonly DependencyProperty IsRequiredProperty =
DependencyProperty.Register("IsRequired", typeof(bool),
typeof(MyUserControl), new FrameworkPropertyMetadata(default(bool)));
public bool IsRequired
{
get { return (bool)GetValue(IsRequiredProperty); }
set { SetValue(IsRequiredProperty, value); }
}
내 사용자 컨트롤보기에서
:
// This is the one I want bound to the dependency property.
bool IsRequired { //INotifyPropertyChanged getter and setter}
public void SomeCommandExec(Object obj)
{
// Update the dependency property by doing this:
IsEnabled = False;
}