如何制作 TextBox 控件 Read-Only

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

示例:

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

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

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

默认值 IsReadOnlyfalse

另请参阅