繁体   English   中英

触发Treeview的SelectedItemChanged事件时,如何聚焦两个文本框?

[英]How to Focus Two Text Boxes as SelectedItemChanged event of Treeview is triggerd?

当用户在treeview中选择treeview项目时,我试图集中两个文本框。 我正在使用SlectedItemChanged事件来实现此目的。 我需要同时集中两个文本框。

    delegate void voiDelegate();
    private void click(object sender, RoutedPropertyChangedEventArgs<object> e)
    {
        TreeViewItem t;
        t =(TreeViewItem) tvMain.SelectedItem;
        StackPanel s = (StackPanel)t.Header;
        List<TextBlock> l = new List<TextBlock>(3);
        foreach (TextBlock children in s.Children)
        {
            l.Add(children);
        }
        string ch = l[3].Text;
        string[] sp = ch.Split('-');
        int te = Convert.ToByte(sp[1]) - Convert.ToByte(sp[0]) + 1;
        PacketDisplay1.SelectionStart = PacketDisplay2.SelectionStart = Convert.ToByte(sp[0]);
        PacketDisplay1.SelectionLength= PacketDisplay2.SelectionLength = te;
        voiDelegate giveFocusDelegate = new voiDelegate(giveFocus);
        Dispatcher.BeginInvoke(giveFocusDelegate, new object[] { });

    }
    private void giveFocus()
    {
        PacketDisplay1.Focus();
        PacketDisplay2.Focus();
    }  

在这里,焦点仅在PacketDisplay2文本框中发生。
如何在两个文本框中都实现聚焦? 谢谢。

不能同时关注两个文本框。 调用PacketDisplay2.Focus()时,PacketDisplay1控件将失去焦点。 这是Windows设计的。

阅读以下链接: https : //msdn.microsoft.com/zh-cn/library/aa969768%28v=vs.110%29.aspx

它说得很清楚: Keyboard focus refers to the element that is currently receiving keyboard input. There can be only one element on the whole desktop that has keyboard focus. Keyboard focus refers to the element that is currently receiving keyboard input. There can be only one element on the whole desktop that has keyboard focus.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM