C# 如何在wpf的堆栈面板中创建动态组合框,检索它们的值并删除它们

C# 如何在wpf的堆栈面板中创建动态组合框,检索它们的值并删除它们,c#,wpf,C#,Wpf,我想在wpf堆栈面板中创建动态组合框,检索它们的值,并在用户在文本框中输入数字时删除它们。以下是我使用的代码,当用户在文本框中输入数字时,(在TextEventChaged上)将组合框添加到stackpanel(即VehiclesPerday): 后端 private void NumberOfVehciles\u TextChanged(对象发送者,textchangedventargs e) { int _count=Convert.ToInt32(NumberOfVehciles.Te

我想在wpf堆栈面板中创建动态组合框,检索它们的值,并在用户在文本框中输入数字时删除它们。以下是我使用的代码,当用户在文本框中输入数字时,(在TextEventChaged上)将组合框添加到stackpanel(即VehiclesPerday):


后端
private void NumberOfVehciles\u TextChanged(对象发送者,textchangedventargs e)
{
int _count=Convert.ToInt32(NumberOfVehciles.Text.Trim());
对于(int x=1;x
  • 我添加了检查文本框中的文本是否为number,是否可以转换为int
  • 添加了仅用于测试的调用
    VehiclesPerday.Children.Clear()
  • 添加了
    foreach
    循环,通过
    Name
private void NumberOfVehciles\u TextChanged(对象发送者,textchangedventargs e)
{
if(int.TryParse(numberofevehciles.Text.Trim(),out int\u count))
{
VehiclesPerday.Children.Clear();//用于测试

对于(int x=1;x)非常感谢先生