2016-11-11 14 views
0

WPFを初めて使用しています。
ボタンをクリックすると、動的TextBoxが表示されます。
テキストボックスにフォーカスが置かれるたびに、グリッドビューが表示されます。
そのgridviewには値のテーブルが含まれています。
1行を入力するとテキストボックスにバインドされますが、値を入力した後にgridviewが表示されても新しい値は表示されません。WPFでデータベース値をTextBoxに動的にバインドする方法

int count = 0;  
    private void button_Click(object sender, RoutedEventArgs e) 
    { 
     TextBox t = new TextBox(); 
     t.MinHeight = 15; 
     t.Width = 100; 
     t.Height = 30; 
     t.Name = "txtPKSourceCode"; 
     t.Text = "{Binding PurchaseOrder.PickupSrcCodeName, Mode=TwoWay}"; 
     ColumnDefinition colDef1; 
     colDef1 = new ColumnDefinition(); 
     mymy.ColumnDefinitions.Add(colDef1); 

     RowDefinition rowDef1; 
     rowDef1 = new RowDefinition(); 
     mymy.RowDefinitions.Add(rowDef1); 
     ++count; 

     mymy.Children.Add(t); 
      Grid.SetColumn(t, 0); 
     Grid.SetRow(t, count); 
    t.GotFocus += t_GotFocus; 

    } 

    private void t_GotFocus(object sender, RoutedEventArgs e) 
    { 
     button.Visibility = Visibility.Hidden; 
     SourceCodeDialog sourcedlg = new SourceCodeDialog("txtPKSourceCode"); 
     sourcedlg.Owner = Window.GetWindow(this); 
     sourcedlg.POWindow = this; 
     var srcresult = sourcedlg.ShowDialog(); 
    } 

答えて

0

バインディングパスとモードを指定できるバインディングクラスのオブジェクトを作成できます。 SetBinding()メソッドを使用して、テキストボックスへのバインディングを設定できます。

TextBox t = new TextBox();

バインディングtxtBinding =新しいバインディング( "PurchaseOrder.PickupSrcCodeName"); txtBinding.Mode = BindingMode.TwoWay;

t.SetBinding(TextBox.TextProperty、txtBinding);

+0

私は –

+0

GridViewの値が新しい値の挿入を必要とするこのように、古いテキストボックスの値がここで結合display.but foはどうもありがとうございました。<:EventTrigger EVENTNAME = "のGotFocus" I> このコードを動的テキストボックスに与えるにはどうすればいいですか? –

関連する問題