/// <summary> /// Shows a simple full screen popup /// </summary> /// <param name="content">Content you want to be presented inside the popup. Simply use typeof(YourUserControl)</param> /// <param name="Host_Id">Id of the control that will host the new popup</param> /// <param name="OpenNewIfExists">Allows to open more than one popup with the same content</param> /// <param name="ShowAnimationMode">Animation mode of showing the popup</param> /// <param name="HideAnimationMode">Animation mode of hiding the popup</param> /// <param name="Margin">Content padding from the sides</param> /// <param name="ShowAnimDuration">Show animation duration</param> /// <param name="HideAnimDuration">Hide animation duration</param> /// <param name="args">Arguments needed on the Content ctor</param> /// <returns></returns> public static Guid ShowPopupControl(Type content, string Host_Id = null, bool OpenNewIfExists = true, PopupControlAnimationKind ShowAnimationMode = PopupControlAnimationKind.FadeIn, PopupControlAnimationKind HideAnimationMode = PopupControlAnimationKind.FadeOut, Thickness?Margin = null, Duration?ShowAnimDuration = null, Duration?HideAnimDuration = null, params object[] args) { PopupPresenterHost Host = null; try { if (Host_Id == null) { Host = _hosts.Any() ? _hosts.FirstOrDefault() : throw new Exception("Mo Hosts found or the host disposed."); } else { Host = _hosts.Any() ? _hosts.First(x => x.Id == Host_Id) : throw new Exception("Mo Hosts found or the host disposed."); } var testthreadaccess = Host.Id; } catch (Exception ex) { if (ex.Message.Contains("0x8001010E")) { foreach (var item in _hosts) { try { if (item.Id is null || item.Id is string str) { if (Host_Id == null) { Host = item; } else if (item.Id == Host_Id) { Host = item; } } } catch { } } } } if (Host.Children.Any(x => x is PopupControl pop && pop.PopupContentType == content)) { if (!OpenNewIfExists) { throw new Exception("An existing popup of this type is currently open."); } } var p = new PopupControl(content, args) { ShowAnimation = ShowAnimationMode, HideAnimation = HideAnimationMode }; if (Margin.HasValue) { p.ContentMargin = Margin.Value; } if (ShowAnimDuration.HasValue) { p.ShowAnimationDuration = ShowAnimDuration.Value; } if (HideAnimDuration.HasValue) { p.HideAnimationDuration = HideAnimDuration.Value; } Host.Children.Add(p); p.ShowPopup(); return(p.Identifier); }
public static async Task <Guid> ShowPopupControlAsync(Type content, string Host_Id = null, bool OpenNewIfExists = true, PopupControlAnimationKind ShowAnimationMode = PopupControlAnimationKind.FadeIn, PopupControlAnimationKind HideAnimationMode = PopupControlAnimationKind.FadeOut, Thickness?Margin = null, Duration?ShowAnimDuration = null, Duration?HideAnimDuration = null, params object[] args) { PopupPresenterHost Host = null; if (Host_Id == null) { Host = _hosts.Any() ? _hosts.FirstOrDefault() : throw new Exception("Mo Hosts found or the host disposed."); } else { Host = _hosts.Any() ? _hosts.First(x => x.Id == Host_Id) : throw new Exception("Mo Hosts found or the host disposed."); } if (Host.Children.Any(x => x is PopupControl.PopupControl pop && pop.PopupContentType == content)) { if (!OpenNewIfExists) { throw new Exception("An existing popup of this type is currently open."); } } var p = new PopupControl.PopupControl(content, args) { ShowAnimation = ShowAnimationMode, HideAnimation = HideAnimationMode }; if (Margin.HasValue) { p.ContentMargin = Margin.Value; } if (ShowAnimDuration.HasValue) { p.ShowAnimationDuration = ShowAnimDuration.Value; } if (HideAnimDuration.HasValue) { p.HideAnimationDuration = HideAnimDuration.Value; } Host.Children.Add(p); await p.ShowPopupAsync(); return(p.Identifier); }