开发者

Issue with focus of a Silverlight Listbox

开发者 https://www.devze.com 2022-12-29 01:05 出处:网络
I have a button and on click of that i show a popup which has a listbox. popup named - popComboList Listbox named - lstComboBoxResult

I have a button and on click of that i show a popup which has a listbox.

popup named - popComboList

Listbox named - lstComboBoxResult

I am giving a focus to a listbox but at initial on a click of a button the listbox doesn't get focus-(this happens only once at initial, when i first time click button) After the second click it works.

 private void bnOpen_Click(object sender, RoutedEventArgs e)
    {
        if (IsDesignTime)
            return;

        lstComboBoxResult.Width = tbComboValue.ActualWidth + bnOpen.ActualWidth;
        if (!popComboList.IsOpen)
        {
          开发者_如何学C  SetPopupPosition(popComboList);
            popComboList.IsOpen = true;
            lstComboBoxResult.Focus();
        }
        else
        {
            popComboList.IsOpen = false;
        }
    }


This is a bit of a guess, but try calling UpdateLayout() after opening the pop-up, but before calling Focus(). It's possible that the listbox is not fully initialized and therefore unable to accept focus until it has become visible for the first time.

0

精彩评论

暂无评论...
验证码 换一张
取 消