如何创建 TextBox 控件 Read-Only

此示例演示如何将 TextBox 控件配置为不允许用户输入或修改。

若要防止用户修改 TextBox 控件的内容,请将 IsReadOnly 属性设置为 true

<TextBox 
  IsReadOnly="True"
>
  The user may not modify the contents of this TextBox.
</TextBox>

IsReadOnly 属性仅影响用户输入;它不会影响 TextBox 控件的可扩展应用程序标记语言(XAML)描述中的文本集,也不影响通过 Text 属性以编程方式设置的文本集。

IsReadOnly 的默认值为 false

另请参阅