punker76 / MahApps.Metro.SimpleChildWindow

A simple child window for MahApps.Metro
MIT License
374 stars 55 forks source link

Trying to call mahapps ShowMessageAsync() from SimpleChildWindow causes exception #90

Closed JohnFredMeyer closed 4 years ago

JohnFredMeyer commented 5 years ago

I am trying to use Mahapps ShowMessageAsync() to have a confirmation dialog for item in SimpleChildWindow. When trying to call the ShowMessageAsync() from the child window I get an exception.

image

System.InvalidOperationException
  HResult=0x80131509
  Zpráva=Sequence contains more than one element
  Zdroj=System.Core
  StackTrace:
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at MahApps.Metro.Controls.Dialogs.DialogManager.AddDialog(MetroWindow window, BaseMetroDialog dialog)
   at MahApps.Metro.Controls.Dialogs.DialogManager.SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog)
   at MahApps.Metro.Controls.Dialogs.DialogManager.<>c__DisplayClass3_0.<ShowProgressAsync>b__1()
   at System.Windows.Threading.DispatcherOperation`1.InvokeDelegateCore()
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation operation, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke[TResult](Func`1 callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke[TResult](Func`1 callback)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MahApps.Metro.SimpleChildWindow.Demo.TestChildWindow2.<Button_Click>d__2.MoveNext() in C:\Users\Pucalka\source\repos\MahApps.Metro.SimpleChildWindow\src\MahApps.Metro.SimpleChildWindow.Demo\TestChildWindow2.xaml.cs:line 38
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at MahApps.Metro.SimpleChildWindow.Demo.App.Main()

Is this possible or can you not call dialog from child window? I can perform nested child windows without issue. So I can use another child window as work around and pass back a bool. Thanks.

punker76 commented 4 years ago

@JohnFredMeyer @Martin-Pucalka This issue will be fixed at MahApps itself. I will close this issue then.

punker76 commented 4 years ago

I transferred the issue to https://github.com/MahApps/MahApps.Metro/issues/3865