我正在研究用于城域网应用的C#和XAML。我有一个文本框,我希望一旦在该文本框中按下输入,就会出现一个新的文本框。但不是只有一个文本框,我有两个文本框。我做了调试也n实现了它的触发两次。无法弄清楚它被触发两次的原因。 这是我的应用程序的一些代码
private void TextBox_KeyDown_1(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
//code for producing textbox
}
}
当我调试时,一旦执行了上面的块,就会转到LayoutAwarePage.cs 并将控件发送到代码片段
private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender,
AcceleratorKeyEventArgs args)
{
var virtualKey = args.VirtualKey;
if ((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown ||
args.EventType == CoreAcceleratorKeyEventType.KeyDown) &&
(virtualKey == VirtualKey.Left || virtualKey == VirtualKey.Right ||
(int)virtualKey == 166 || (int)virtualKey == 167))
{
var coreWindow = Window.Current.CoreWindow;
var downState = CoreVirtualKeyStates.Down;
bool menuKey = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
bool shiftKey = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;
bool noModifiers = !menuKey && !controlKey && !shiftKey;
bool onlyAlt = menuKey && !controlKey && !shiftKey;
if (((int)virtualKey == 166 && noModifiers) ||
(virtualKey == VirtualKey.Left && onlyAlt))
{
// When the previous key or Alt+Left are pressed navigate back
args.Handled = true;
this.GoBack(this, new RoutedEventArgs());
}
else if (((int)virtualKey == 167 && noModifiers) ||
(virtualKey == VirtualKey.Right && onlyAlt))
{
// When the next key or Alt+Right are pressed navigate forward
args.Handled = true;
this.GoForward(this, new RoutedEventArgs());
}
}
}
一旦完成代码块,控件就会被发送回函数TextBox_KeyDown_1。我能够理解为什么在第一位控件被发送到layoutawarepage.cs。当我在项目中添加SplitPage时生成了此代码。