1

MainWindow に静的リストがあります。変更が発生した場合、CurrValue はすぐに設定されます。

public static List<varVisu> varVisuListDll = new List<varVisu>();

私のクラスには、 INotifyPropertyChanged 実装があります

    public string m_CurrValue;

    public event PropertyChangedEventHandler PropertyChanged;
    protected void Notify(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public string CurrValue
    {
        get { return m_CurrValue; }
        set 
        {
            if (value != m_CurrValue)
            {
                //set value
                m_CurrValue = value;
                //notify anyone who cares about it
                Notify("CurrValue");
            }
        }
    }

これは問題なく動作しますが、今回は Window#2 の Textbox (Text)をこの List の最初の項目 (varVisuListDll[0].CurrValue) にバインドしたいと考えています。

TextBox.Text をこの値にバインドするにはどうすればよいですか (Text={Path, UpdateSourceTrigger ...}??

<TextBox x:Name="txtManualMode" Text="{Binding ElementName=????, Path=CurrValue, UpdateSourceTrigger=PropertyChanged}" 

(dtgrVariables.ItemSource=MainWindow.varVisuListDll) でテストしました。この作品の.

私を助けてください ..

4

2 に答える 2

0

varVisuListDllフィールドではなく、プロパティでなければなりません:

private static List<varVisu> varVisuListDll = new List<varVisu>();

public static List<varVisu> VarVisuListDll
{
    get { return varVisuListDll; }
}

次に、バインディングは次のようになります。

<TextBox Text="{Binding Path=(local:MainWindow.VarVisuListDll)[0].CurrValue}"/>

または、.NET 4 よりも古いフレームワークを使用している場合:

<TextBox Text="{Binding Path=[0].CurrValue,
                        Source={x:Static local:MainWindow.VarVisuListDll}}"/>
于 2015-09-08T07:57:17.993 に答える