0

私は現在、次のものを持っています:

public static readonly DependencyProperty IsCopyEnabledProperty =
    DependencyProperty.Register(
        "IsCopyEnabled",
        typeof(bool),
        typeof(MainWindow));

    public bool IsCopyEnabled
    {
        get { return (bool)GetValue(IsCopyEnabledProperty); }
        set { SetValue(IsCopyEnabledProperty, value); }
    }

これを作成したボタンにバインドして、有効にするか無効にするかを決定します。私は通常、宣言されているクラスから IsCopyEnabled の値を変更するために次を呼び出します。

IsCopyEnabled = !IsCopyEnabled;

IsCopyEnabled の値を別のクラス (同じ名前空間) で変更する方法を考えています。

4

2 に答える 2

0

SetValue はパブリック メソッドです。ターゲット オブジェクトへの参照がある場合は、別のクラスから呼び出すことができます。

Button button = new Button();
button.SetValue(Button.IsEnabledProperty, !(bool)button.GetValue(Button.IsEnabledProperty));
于 2013-10-01T17:36:25.043 に答える
0

クラス インスタンスごとの他のクラス プロパティと同様です。

MainWindow window = new MainWindow();
window.IsCopyEnabled = !window.IsCopyEnabled;

MainWindow の DP を登録したので、これを行うこともできます

Application.Current.MainWindow.IsCopyEnabled = !Application.Current.MainWindow.IsCopyEnabled;
于 2013-10-01T17:30:24.037 に答える