(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;
}