2013-12-17 85 views
0

到現在爲止,我只需要在堆疊面板上顯示一些複選框。因此,我以動態插入文本框

的步驟來構建複選框的內容。

public void addAlarmcl(string argComparator, string value, string argColor) 
     { 
      if ((!string.IsNullOrEmpty(argComparator)) && (!string.IsNullOrEmpty(value)) && (!string.IsNullOrEmpty(argColor))) 
      { 
       //hexadecimal of color chosen 
       Color color = (Color)ColorConverter.ConvertFromString(argColor); 
       //this is to be displayed in stackpenl 
       string TheOneYouJustBuilt = "If statistics are /" + argComparator + "/" + value + "/ ,notify by /" + color + "/."; 
       addToStackPanel(TheOneYouJustBuilt); 
      } 

     } 

,然後將其添加到堆棧面板

//this will display the built alarms on the stackpanel 
     public void addToStackPanel(string argBuiltAlarm) 
     { 
      CheckBox checkQueries = new CheckBox() { Content = argBuiltAlarm }; 
      stackPanel1.Children.Add(checkQueries); 
      AlarmList.Add(checkQueries); 
      //storing the built queries alongside FOR DELETION (OR OTHER REFERENCES) 
      AlarmThatIsBeingDisplayed.Add(argBuiltAlarm.ToString()); 
     } 

但現在我需要一個文本框在複選框結束content.How修改我的代碼添加一個文本框?

我知道,聲明一個新的文本框,我們做

var textbox = new TextBox(); 
//thn we set its properties and all 

但我怎麼剛剛複選框內容之後追加了嗎?

回答

1

試試這個代碼

public void addToStackPanel(string argBuiltAlarm) 
{ 
    //creating a stackpanel with orientation horizontal 
    StackPanel stackPanel=new StackPanel 
     { 
      Orientation =System.Windows.Controls.Orientation.Horizontal 
     }; 

    TextBox textBox=new TextBox{ Text = "your text"}; 

    CheckBox checkQueries = new CheckBox() { Content = argBuiltAlarm }; 

    stackPanel.Children.Add(checkQueries); 
    stackPanel.Children.Add(textBox); 

    //adding the stackpanel containing both checkbox & textbox to the stackPanel1 
    stackPanel1.Children.Add(stackPanel); 

    //remaining codes here 

} 
+0

解決方案。他的作品非常棒。特克斯。在一分鐘內+1。 –

0

你需要用一些容器複選框和文本框:StackPanel中或網格:

var sp = new StackPanel() 
{ 
    Orientation = Orientation.Horizontal 
}; 
sp.Children.Add(checkQueries); 
sp.Children.Add(textbox); 
stackPanel1.Children.Add(sp); 
+0

Tony.I沒有得到文本框。我得到複選框及其內容,並在它後面我得到系統....文本框。但沒有出現文本框。 –