【发布时间】:2014-09-30 20:46:49
【问题描述】:
这个 NumericUpDown (NUD) 漂浮在地图上。当它变得可见时,我需要重定向控件内的下一个击键来覆盖当前值。
我非常痛苦地找到了这个解决方案:
private void LengthInput_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if ((bool)(e.NewValue))
{
...
LengthInputBox.ShowButtons = true;
try
{
LengthInputBox.Focus();
if (m_lengthTextBox == null)
{
LengthInputBox.ApplyTemplate();
m_lengthTextBox = LengthInputBox.Template.FindName("textbox", LengthInputBox) as TextBox;
}
if (m_lengthTextBox != null)
{
m_lengthTextBox.SelectAll();
m_lengthTextBox.Focus();
}
}
finally
{
LengthInputBox.ShowButtons = false;
}
...
NUD 是 LengthInputBox 控件。 Focus 方法将焦点设置在 NUD 按钮上。
Template.FindName("textbox"... 检索 NUD 的内部 TextBox。如果找到,或者以前找到,则选择全部并设置焦点在文本上。
最后,我删除了向上/向下按钮(我不需要它们。尽管我已经做了很多有或没有它们的变化,但它们的存在并不会改变行为......)
第一次成功,第二次又失败了。
有什么想法吗?
【问题讨论】: