Lets say I have an AutoCompleteBox with 1000 items.
- A user first types two characters returning a broad result set (for example, 100 items).
- They then scroll to the bottom of the list and...
- They then select the last item which clo开发者_JAVA技巧ses the dropdown.
- The user then returns to the AutoCompleteBox and enters a more refined search returning, say, 25 items.
- Because the previously selected item was at the bottom of the dropdown, the AutoCompleteBox shows the last element(s) of the new search result, instead of displaying the first items at the top of the list.
How do I force the AutoCompleteBox to display the results starting with the first item in the list?
Here is a blind guess based on the default control templates. In DropdownOpening
event:-
var sv = ((FrameworkElement)sender).FindName("ScrollViewer") As ScrollViewer;
if (sv != null)
sv.VerticalOffset = 0;
I know this is not much of an answer, but I thought I would share what I discovered, even though it does not solve the problem. I tried all the following in the DropDownOpening
event.
- Set the
SelectedItem
to null. - Failed. - Follow what Anthony suggested. - Failed. First off,
sender
isAutoCompleteBox
and does not containScrollViewer
. Second,VerticalOffset
is read-only. - I checked all the variables in
AutoCompleteBox
and found that it has a non-public variable calledDropDownPopup
that is an instance ofSystem.Windows.Control.PopupHelper
. I could not find it in that library though. It does however, contain aPopup
property with a variableVerticalOffset
. However, I tried to inheritAutoCompleteBox
and was unable to access that variable, so I suspect it must be private.
精彩评论