此範例顯示如何使用 Text 屬性來設定 TextBox 控制項的初始文字內容。
備註
雖然範例的 Extensible Application Markup Language (XAML) 版本可以使用每個按鈕 TextBox 內容文字周圍的 <TextBox.Text> 標籤,但不需要這麼做,因為 TextBox 會將 ContentPropertyAttribute 屬性套用至 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."
另請參閱
- TextBox 概觀
- RichTextBox 概述