本主题中的示例演示如何将 TextBox 控件配置为禁止用户输入或修改。
示例
为了防止用户修改 TextBox 控件的内容,请将 IsReadOnly 特性设置为 true。
<TextBox
IsReadOnly="True"
>
The user may not modify the contents of this TextBox.
</TextBox>
IsReadOnly 特性仅影响用户输入,而不会影响在 TextBox 控件的Extensible Application Markup Language (XAML) 说明中设置的文本或者通过 Text 属性以编程方式设置的文本。
IsReadOnly 的默认值为 false。