簡體   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