System.Windows.Controls.AutoCompleteBox.PopulateComplete C# (CSharp) Méthode

PopulateComplete() public méthode

Notifies the T:System.Windows.Controls.AutoCompleteBox that the P:System.Windows.Controls.AutoCompleteBox.ItemsSource property has been set and the data can be filtered to provide possible matches in the drop-down.
Call this method when you are providing custom population of the drop-down portion of the AutoCompleteBox, to signal the control that you are done with the population process. Typically, you use PopulateComplete when the population process is a long-running process and you want to cancel built-in filtering of the ItemsSource items. In this case, you can handle the Populated event and set PopulatingEventArgs.Cancel to true. When the long-running process has completed you call PopulateComplete to indicate the drop-down is populated.
public PopulateComplete ( ) : void
Résultat void
        public void PopulateComplete()
        {
            // Apply the search filter
            RefreshView();

            // Fire the Populated event containing the read-only view data.
#if SILVERLIGHT
            PopulatedEventArgs populated = new PopulatedEventArgs(new ReadOnlyCollection<object>(_view));
#else
            PopulatedEventArgs populated = new PopulatedEventArgs(new ReadOnlyCollection<object>(_view), PopulatedEvent);
#endif
            OnPopulated(populated);

            // ReSharper disable once PossibleUnintendedReferenceComparison
            if(SelectionAdapter != null && SelectionAdapter.ItemsSource != _view)
            {
                SelectionAdapter.ItemsSource = _view;
            }

            bool isDropDownOpen = _userCalledPopulate && _view.Count > 0;
            if(isDropDownOpen != IsDropDownOpen)
            {
                _ignorePropertyChange = true;
                IsDropDownOpen = isDropDownOpen;
            }
            if(IsDropDownOpen)
            {
                OpeningDropDown(false);
                if(DropDownPopup != null)
                {
                    DropDownPopup.Arrange();
                }
            }
            else
            {
                ClosingDropDown(true);
            }

            UpdateTextCompletion(_userCalledPopulate);
        }

Usage Example

Exemple #1
0
        void UpdateQueryResults(AutoCompleteBox box, Task<object[]> task, CancellationToken token)
        {
            VerifyAccess();
            //
            // Last chance for cancellation... after this, we know we won't get canceled because cancellation can
            // only happen on this thread.
            //
            if (task.Status != TaskStatus.RanToCompletion || token.IsCancellationRequested) { return; }

            box.ItemsSource = task.Result;
            box.PopulateComplete();
        }