【发布时间】:2018-04-06 05:03:04
【问题描述】:
当文本框失去焦点时,我正在验证输入的数据。 当我的验证规则将 TextBox 的内容识别为无效时,我想自动将焦点返回到 TextBox。 我的理由是,如果用户必须重新输入有效数据,我可以通过为他们预先定位光标来为他节省一次击键。
我将 TextBox 的名称传递给验证类,就像这样...
<TextBox x:Name="addAnInteger">
<Binding.ValidationRules>
<local:ValidateInteger32 TextBoxName="addAnInteger"/>
</Binding.ValidationRules>
</TextBox>
在验证类 (ValidateInteger32) 我有:
public string TextBoxName { get; set; }
属性 TextBoxName 接收并存储我想要将焦点重置到的 TextBox 的名称。
如何仅使用属性 TextBoxName 的名称从 ValidateInteger32 验证类内部将焦点设置回“addAnInteger”文本框?我在想类似......
[Commands that expose the contents of TextBoxName].Focus();
我不想在验证类中使用单个文本框的名称,因为我希望该类是通用的。
感谢任何建议。
【问题讨论】:
标签: c# wpf xaml data-binding