2015-04-08 24 views
0

我是WPF的新手,遇到了一種情況,我認爲動態添加控件會很好。添加WPF控件動態使用代碼

但我不知道是否有是動態使用代碼。我要添加使用代碼

<WrapPanel Height="39"> 
     <TextBox Width="93" Margin="-1,5,0,0"></TextBox> 
     <TextBox Width="76" Margin="0,5,0,0"></TextBox> 
     <TextBox Width="70" Margin="0,5,0,0"></TextBox> 
     <TextBox Width="70" Margin="0,5,0,0"></TextBox> 
     <TextBox Width="127" Margin="0,5,0,0"></TextBox> 
     <TextBox Width="100" Margin="0,5,0,0"/> 
</WrapPanel> 

我試過THIS方法如下,但它沒有工作

+0

@bit我試過這種方法,但它沒有工作,所以我發佈了新的問題 – Richa

+0

你能說出你試過了什麼嗎? – bit

+0

你聲稱沒有工作的代碼應該可以工作。發佈你的代碼不起作用。 –

回答

0

試試下面的代碼

var panel = new WrapPanel() { Height = 39 }; 
      panel.Children.Add(new TextBox() { Width = 93, Margin = new Thickness(-1, 5, 0, 0) }); 
      panel.Children.Add(new TextBox() { Width = 76, Margin = new Thickness(0, 5, 0, 0) }); 
      panel.Children.Add(new TextBox() { Width = 70, Margin = new Thickness(0, 5, 0, 0) }); 
      panel.Children.Add(new TextBox() { Width = 70, Margin = new Thickness(0, 5, 0, 0) }); 
      panel.Children.Add(new TextBox() { Width = 127, Margin = new Thickness(0, 5, 0, 0) }); 
      panel.Children.Add(new TextBox() { Width = 100, Margin = new Thickness(0, 5, 0, 0) }); 
      this.Content = panel; 
+0

謝謝,正準備嘗試。但你做得更快。感謝您的工作 – Richa

+0

如何設置高度自動或文字環繞 – Richa

+0

刪除WrapPanel高度將在內部視爲自動 –