Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Hosting WPF control in Windows Forms Application

$
0
0

Hi,

In my WPF control, i have implemented asynchronous pattern to perform non UI tasks by the following way.

        internal static void Execute(Action action)
        {
            if (System.Windows.Application.Current != null)
            {
                if (System.Windows.Application.Current.Dispatcher.CheckAccess())
                    action();
                else
                    System.Windows.Application.Current.Dispatcher.BeginInvoke(action, null).Wait();
            }
        }

This works fine for WPF applications. When i used my WPF control in Windows Forms Application with the help of ElementHost, i am not able to use the above method, since System.Application.Current will be null.

Now I have to know the following things.

1) Is it possible to access UI thread within my WPF control, when the control has been hosted in Windows Forms Application?

2) If possible, kindly guide me how to achieve it.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>