How to return a value with Dispatcher.Invoke?

后端 未结 5 1982
执念已碎
执念已碎 2020-12-20 10:42

Anyone knows how to return a value from Dispatcher.Invoke in wpf? I want to return the selected index for a ComboBox.

Thanks!

5条回答
  •  执念已碎
    2020-12-20 11:31

    There's another way that returns value from Invoke():

    object oIsLoaded = container.Dispatcher.Invoke( new Func ( () =>
        {
            return container.IsLoaded;
        })
    );
    

    And by the way, chances are that the initial code (which is working with delegate) won't modify oIsLoaded at all; So I'd rather use a Func<> for returning a value from that kind of function.

提交回复
热议问题