Issue with focus of a Silverlight Listbox
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.
精彩评论