如何:设置 TextBox 控件的文本内容

此示例演示如何使用 Text 属性设置 TextBox 控件的初始文本内容。

注释

尽管该示例的可扩展应用程序标记语言(XAML)版本可以在每个按钮的TextBox内容文本周围使用<TextBox.Text>标记,但这并不是必须的,因为TextBoxContentPropertyAttribute属性应用于Text属性。 有关详细信息,请参阅 WPF 中的 XAML

使用 Text 属性设置文本内容

<TextBox Name="tbSettingText">
  Initial text contents of the TextBox.
</TextBox>

设置 TextBox 控件的文本内容

tbSettingText.Text = "Initial text contents of the TextBox.";
tbSettingText.Text = "Initial text contents of the TextBox."

另请参阅