0

TextBox.TextWFPアプリケーションのプロパティをEFエンティティオブジェクトのプロパティにバインドしたい。

エンティティオブジェクトの初期化は次のとおりです。

public static Question CurrentQuestion = new Question
       {
             Description = "How old are you?"
       };

そして、これがテキストボックスをデータバインドする関数です:

private void BindQuestionControls()
        {
            Binding b = new Binding();
            b.Source = CurrentQuestion;
            b.Mode = BindingMode.TwoWay;
            b.Path = new PropertyPath("Description");
            textBoxQuestion.SetBinding(TextBlock.TextProperty, b);
        }

アプリが起動すると、textBoxQuestionに「あなたは何歳ですか?」と表示されると思います。ただし、空です。宣言でバインディングを設定することをお勧めします。これを行う方法を提案してください。ありがとう。

4

1 に答える 1

0

すべきではない

textBoxQuestion.SetBinding(TextBlock.TextProperty, b);

しかし

textBoxQuestion.SetBinding(TextBox.TextProperty, b);
于 2013-01-09T16:59:36.633 に答える