Skip to content

Commit

Permalink
Merge pull request #129 from punker76/feat/#68-open-child-window-on-c…
Browse files Browse the repository at this point in the history
…ontrol

Open child window on controls and not only window
  • Loading branch information
punker76 committed Oct 3, 2022
2 parents b034499 + f5c2676 commit 49676fc
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/MahApps.Metro.SimpleChildWindow/ChildWindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum OverlayFillBehavior
/// <summary>
/// Shows the given child window on the MetroWindow dialog container in an asynchronous way.
/// </summary>
/// <param name="window">The owning window with a container of the child window.</param>
/// <param name="control">The owning control with a container for the child window.</param>
/// <param name="dialog">A child window instance.</param>
/// <param name="overlayFillBehavior">The overlay fill behavior.</param>
/// <returns>
Expand All @@ -41,16 +41,16 @@ public enum OverlayFillBehavior
/// or
/// The provided child window is already visible in the specified window.
/// </exception>
public static Task ShowChildWindowAsync(this Window window, ChildWindow dialog, OverlayFillBehavior overlayFillBehavior = OverlayFillBehavior.WindowContent)
public static Task ShowChildWindowAsync(this Control control, ChildWindow dialog, OverlayFillBehavior overlayFillBehavior = OverlayFillBehavior.WindowContent)
{
return window.ShowChildWindowAsync<object>(dialog, overlayFillBehavior);
return control.ShowChildWindowAsync<object>(dialog, overlayFillBehavior);
}

/// <summary>
/// Shows the given child window on the MetroWindow dialog container in an asynchronous way.
/// When the dialog was closed it returns a result.
/// </summary>
/// <param name="window">The owning window with a container of the child window.</param>
/// <param name="control">The owning control with a container for the child window.</param>
/// <param name="dialog">A child window instance.</param>
/// <param name="overlayFillBehavior">The overlay fill behavior.</param>
/// <returns>
Expand All @@ -61,14 +61,14 @@ public static Task ShowChildWindowAsync(this Window window, ChildWindow dialog,
/// or
/// The provided child window is already visible in the specified window.
/// </exception>
public static async Task<TResult> ShowChildWindowAsync<TResult>(this Window window, ChildWindow dialog, OverlayFillBehavior overlayFillBehavior = OverlayFillBehavior.WindowContent)
public static async Task<TResult> ShowChildWindowAsync<TResult>(this Control control, ChildWindow dialog, OverlayFillBehavior overlayFillBehavior = OverlayFillBehavior.WindowContent)
{
var tcs = new TaskCompletionSource<TResult>();

window.Dispatcher.VerifyAccess();
control.Dispatcher.VerifyAccess();

var metroDialogContainer = window.Template.FindName("PART_MetroActiveDialogContainer", window) as Grid;
metroDialogContainer = metroDialogContainer ?? window.Template.FindName("PART_MetroInactiveDialogsContainer", window) as Grid;
var metroDialogContainer = control.Template.FindName("PART_MetroActiveDialogContainer", control) as Grid;
metroDialogContainer = metroDialogContainer ?? control.Template.FindName("PART_MetroInactiveDialogsContainer", control) as Grid;
if (metroDialogContainer == null)
{
throw new InvalidOperationException("The provided child window can not add, there is no container defined.");
Expand All @@ -92,7 +92,7 @@ public static async Task<TResult> ShowChildWindowAsync<TResult>(this Window wind
/// Shows the given child window on the given container in an asynchronous way.
/// When the dialog was closed it returns a result.
/// </summary>
/// <param name="window">The owning window with a container of the child window.</param>
/// <param name="control">The owning control with a container for the child window.</param>
/// <param name="dialog">A child window instance.</param>
/// <param name="container">The container.</param>
/// <returns></returns>
Expand All @@ -101,15 +101,15 @@ public static async Task<TResult> ShowChildWindowAsync<TResult>(this Window wind
/// or
/// The provided child window is already visible in the specified window.
/// </exception>
public static Task ShowChildWindowAsync(this Window window, ChildWindow dialog, Panel container)
public static Task ShowChildWindowAsync(this Control control, ChildWindow dialog, Panel container)
{
return window.ShowChildWindowAsync<object>(dialog, container);
return control.ShowChildWindowAsync<object>(dialog, container);
}

/// <summary>
/// Shows the given child window on the given container in an asynchronous way.
/// </summary>
/// <param name="window">The owning window with a container of the child window.</param>
/// <param name="control">The owning control with a container for the child window.</param>
/// <param name="dialog">A child window instance.</param>
/// <param name="container">The container.</param>
/// <returns />
Expand All @@ -118,11 +118,11 @@ public static Task ShowChildWindowAsync(this Window window, ChildWindow dialog,
/// or
/// The provided child window is already visible in the specified window.
/// </exception>
public static async Task<TResult> ShowChildWindowAsync<TResult>(this Window window, ChildWindow dialog, Panel container)
public static async Task<TResult> ShowChildWindowAsync<TResult>(this Control control, ChildWindow dialog, Panel container)
{
var tcs = new TaskCompletionSource<TResult>();

window.Dispatcher.VerifyAccess();
control.Dispatcher.VerifyAccess();

if (container == null)
{
Expand Down

0 comments on commit 49676fc

Please sign in to comment.