开发者

How to reset the position within the dropdown of a Silverlight AutoCompleteBox

开发者 https://www.devze.com 2022-12-08 07:35 出处:网络
Lets say I have an AutoCompleteBox with 1000 items. A user first types two characters returning a broad result set (for example, 100 items).

Lets say I have an AutoCompleteBox with 1000 items.

  1. A user first types two characters returning a broad result set (for example, 100 items).
  2. They then scroll to the bottom of the list and...
  3. They then select the last item which clo开发者_JAVA技巧ses the dropdown.
  4. The user then returns to the AutoCompleteBox and enters a more refined search returning, say, 25 items.
  5. 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 DropDownOpeningevent.

  1. Set the SelectedItem to null. - Failed.
  2. Follow what Anthony suggested. - Failed. First off, sender is AutoCompleteBox and does not contain ScrollViewer. Second, VerticalOffset is read-only.
  3. I checked all the variables in AutoCompleteBox and found that it has a non-public variable called DropDownPopup that is an instance of System.Windows.Control.PopupHelper. I could not find it in that library though. It does however, contain a Popup property with a variable VerticalOffset. However, I tried to inherit AutoCompleteBox and was unable to access that variable, so I suspect it must be private.
0

精彩评论

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