/// <summary> /// Hides an existing popup /// </summary> /// <param name="Identifier">Identifier of the slideup popup</param> /// <param name="Host_Id">Identifier of the host control</param> public static async void HidePopupControl(Guid Identifier, string Host_Id = null) { PopupPresenterHost Host = null; try { if (Host_Id == null) { Host = _hosts.Any() ? _hosts.FirstOrDefault(x => x.Children.Any(y => y.GetType() == typeof(PopupControl) && (y as PopupControl).Identifier == Identifier)) : throw new Exception("Mo Hosts found or the host disposed."); } else { Host = !_hosts.Any() ? throw new Exception("Mo Hosts found or the host disposed.") : _hosts.Any(x => x.Id == Host_Id) ? _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 && item.Children.Any(y => y.GetType() == typeof(PopupControl) && (y as PopupControl).Identifier == Identifier)) { Host = item; } else if (item.Id == Host_Id && item.Children.Any(y => y.GetType() == typeof(PopupControl) && (y as PopupControl).Identifier == Identifier)) { Host = item; } } } catch { } } if (Host == null) { throw new Exception("Mo Hosts found or the host disposed."); } } } //if (Host_Id == null) // Host = _hosts.Any() ? _hosts.FirstOrDefault(x => x.Children.Any(y => y.GetType() == typeof(PopupControl) && (y as PopupControl).Identifier == Identifier)) : throw new Exception("Mo Hosts found or the host disposed."); //else Host = !_hosts.Any() ? throw new Exception("Mo Hosts found or the host disposed.") : //_hosts.Any(x => x.Id == Host_Id) ? _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 uc && uc.Identifier == Identifier)) { var uc = (PopupControl)Host.Children.FirstOrDefault(x => x is PopupControl uc && uc.Identifier == Identifier); uc.HidePopup(); await Task.Delay((int)uc.HideAnimationDuration.TimeSpan.TotalMilliseconds); uc.Dispose(); Host.Children.Remove(uc); } }
/// <summary> /// This method will shows the message box frame Asynchronously /// </summary> /// <returns></returns> public static async Task <Guid> ShowMessageBoxAsync(string message, Type content = null, string Title = "", string Host_Id = null, MessageBoxCommand[] Commands = null, params object[] args) { PopupPresenterHost Host = null; try { if (Host_Id == null) { Host = _hosts.Any() ? _hosts.FirstOrDefault() : null; } else { Host = _hosts.Any() ? _hosts.First(x => x.Id == Host_Id) : null; } 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 == null) { var msg = new MessageDialog(message, Title); if (Commands != null && Commands.Any()) { foreach (var item in Commands) { msg.Commands.Add(new UICommand(item.Label, delegate { item._invoke?.Invoke(); })); } } await msg.ShowAsync(); return(Guid.Empty); } return(await PopupPresenterHost.ShowSlideupPopupAsync(typeof(MessageBoxControl), Host_Id : Host_Id, PopupMaxWidth : 600, args : new object[] { content == null ? message : content, Title, Commands, args })); }
/// <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); }
/// <summary> /// Shows a simple slideup popup just like Instagram's popups /// </summary> /// <param name="content">Content you want to be presented inside the popup. Simply use typeof(YourUserControl)</param> /// <param name="ContentHeight">Height of the result popup</param> /// <param name="PopupWidth">Width of the result popup</param> /// <param name="PopupMaxWidth">Maximum Width of the result popup</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="BgColor">Background Color of the final popup (default is White)</param> /// <param name="lightdismissbgcolor">Background Color of the popup's light dismiss area</param> /// <param name="args">Arguments needed on the Content ctor</param> /// <returns></returns> public static async Task <Guid> ShowSlideupPopupAsync(Type content, double ContentHeight = double.NaN, double PopupWidth = double.NaN, string Host_Id = null, bool OpenNewIfExists = true, bool IsLightDismissHidingEnabled = true, Brush BgColor = null, Color?lightdismissbgcolor = null, double PopupMaxWidth = double.NaN, 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_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 SlideupPopup slideup && slideup.PopupContentType == content)) { if (!OpenNewIfExists) { throw new Exception("An existing popup of this type is currently open."); } } var p = new SlideupPopup(content, args) { LightDismissEnabled = IsLightDismissHidingEnabled, PopupHeight = ContentHeight }; if (BgColor != null) { p.BackgroundColorBrsh = BgColor; } if (lightdismissbgcolor != null) { p.LightDismissColor = lightdismissbgcolor; } if (!double.IsNaN(PopupWidth)) { p.PopupWidth = PopupWidth; } if (!double.IsNaN(PopupMaxWidth)) { p.PopupMaxWidth = PopupMaxWidth; } Host.Children.Add(p); await p.ShowPopupAsync(); return(p.Identifier); }