如何附加到文本框中的文本

How do I append to Text in textbox

我正在开发一个简单的程序,其中包含一些按钮、一个文本框和一些组合框。

我想做的是,当我再次单击按钮时,结果必须再次出现在文本框中,并且不删除以前的结果,例如在组合框 1 i select bmw 和组合框 2 i 中select germany 在我单击按钮后文本显示在文本框中,我想再次选择其他项目,但之前的项目(bmw 和 germany)应该留在文本框中。我不知道我能不能解释一下。

    <StackPanel>
<ComboBox Name="cb1" Margin="0,10,0,0" Width="100">
    <ComboBoxItem Content="Peugeot"/>
    <ComboBoxItem Content="BMW"/>
    <ComboBoxItem Content="GOLF"/>
</ComboBox>

<ComboBox Name="cb2" Margin="0,10,0,0">
    <ComboBoxItem Content="Usa"/>
    <ComboBoxItem Content="Germany"/>
    <ComboBoxItem Content="France"/>
</ComboBox>

<TextBox Name="txt1" Margin="0,10,0,0" Width="200" Height="100"/>
<Button Name="btnclick" Margin="0,10,0,0" Width="50" Height="30" Content="Click" Click="btnclick_Click" />


     public MainWindow()
{
    InitializeComponent();
}

private void btnclcik_Click(object sender, RoutedEventArgs e)
{
    if (cb1.IsArrangeValid == true)
        if (cb2.IsArrangeValid == true)
            txt1.Text = "Car:" + cb1.Text + "\n" + "state:" + cb2.Text;

}

private void btndel_Click(object sender, RoutedEventArgs e)
{
    cb1.Text = "";
    cb2.Text = "";

}

} }

您需要附加到文本而不是重新设置它...

改成这个..

private void btnclick_Click(object sender, RoutedEventArgs e)
        {
            if (cb1.IsArrangeValid == true)
                if (cb2.IsArrangeValid == true)
                    txt1.Text = (txt1.Text + "\n" + "Car:" + cb1.Text + "\n" + "state:" + cb2.Text).Trim();

        }

and there is no postback in wpf. please do read about it, its not just assignment its going to be your learning