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

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

注意

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

使用文本属性设置文本内容

<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."

另请参阅