开发者

ComboBox items loaded event wpf?

I have a combobox which has ItemsSource set to an ObservableCollection proper开发者_StackOverflowty called DATA via binding. This list has huge data so it will take some time for the combo box to fully load all the items.

I have a background worker that gets all info and sets the ObservableCollection property DATA when done. While this is happening I show a progress indicator, However, after I set the ObservableCollection DATA the UI still seems to hang for quite a while and then the combobox gets loaded up will all items.

Is there an event on combobox that lets me know when all the items have been correctly rendered in the UI?

Thanks


You can use the following code as reference, and here the progress bar and search both are running in same thread, and Dispatcher is being used to notifiy the UI:

        DoWorkEventHandler workHandler = null;
        RunWorkerCompletedEventHandler doneHandler = null;
        Action<parameters> actionCompleted = null;

        BackgroundWorker worker = new BackgroundWorker();

        worker.DoWork += workHandler =
            delegate
            (
                object oDoWrk,
                DoWorkEventArgs eWrk
            )
            {
                worker.DoWork -= workHandler;
                ServiceProxy service = new ServiceProxy();
                service.EventWorkCompleted += actionCompleted =
                    delegate(<parameters>)
                    {
                        service.MethodWorkCompleted -= actionCompleted;
                        currentDispatcher.BeginInvoke(
                            new Action<<parameters>>(
                                OnActionCompleted ), <parameters>);
                    };

                Messenger.Default.Send(
                    new ShowProgressViewMessage( new ProgressViewModel( "Loading..." ) ) );

                service.ServiceMethod();
            };

        worker.RunWorkerCompleted += doneHandler =
            delegate
            (
                object oDone,
                RunWorkerCompletedEventArgs eDone
            )
            {
                Logger.LogVerbose( "Method Called" );

                worker.RunWorkerCompleted -= doneHandler;
            };

        worker.RunWorkerAsync();


    private
    void OnActionCompleted(<parameters>)
    {
    }

Update: Just change the implementation because of copyright issues, hope you don't mind.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜