tags:

views:

22

answers:

1

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)
        {
            SetPopupPosition(popComboList);
            popComboList.IsOpen = true;
            lstComboBoxResult.Focus();
        }
        else
        {
            popComboList.IsOpen = false;
        }
    }
+1  A: 

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.

Eric Mickelsen
Hey Hi tehMick, your guess was right..it worked calling the UpdateLayout after opening the pop-up.. Tx..three cheers for u r guess :) :)
Malcolm