Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Application.OpenForms[0]。在WPF中调用所需的等效项_C#_Wpf - Fatal编程技术网

C# Application.OpenForms[0]。在WPF中调用所需的等效项

C# Application.OpenForms[0]。在WPF中调用所需的等效项,c#,wpf,C#,Wpf,我需要应用程序的等效项。OpenForms[0]。WinForms for wpf中需要调用。我尝试了 var dispatcher = myDispatcherObject.Dispatcher; if (dispatcher.CheckAccess()) { /* ... */ } 但是运气不好请尝试以下扩展方法: public static void TryToExecuteOnUI(this Action uiAction) { var uiDispat

我需要应用程序的等效项。OpenForms[0]。WinForms for wpf中需要调用。我尝试了

var dispatcher = myDispatcherObject.Dispatcher;
if (dispatcher.CheckAccess()) { /* ... */ }

但是运气不好

请尝试以下扩展方法:

    public static void TryToExecuteOnUI(this Action uiAction)
    {
        var uiDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
        if (uiDispatcher.CheckAccess() == false)
        {
            uiDispatcher.Invoke(uiAction);
            return;
        }

        uiAction();
    }

非常感谢你!!!不客气:)