public override void Dispose() { _closure?.Unsubscribe(true, _isOneTime); _bindingSource.Dispose(); ValueChanging = null; ValueChanged = null; _closure = null; base.Dispose(); }
protected virtual Action ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource <object> tcs) { #if WPF var placementTarget = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive); #elif WINDOWS_PHONE var placementTarget = Application.Current.RootVisual as FrameworkElement; #elif WINDOWS_UWP || NETFX_CORE var placementTarget = Window.Current; #endif if (placementTarget == null) { return(null); } var popup = TryGetPopupFromTemplate(content, placementTarget) ?? GetToastPopup(GetToastContentWrapper(GetToastContent(content))); #if WPF popup.PlacementTarget = placementTarget; #endif UpdatePosition(placementTarget, popup, position); popup.IsOpen = true; var closure = new EventClosure(popup, position, placementTarget) { TaskCompletionSource = tcs }; ServiceProvider.AttachedValueProvider.AddOrUpdate(placementTarget, PopupAttachedValuePath, (window, o) => (EventClosure)o, (item, value, currentValue, state) => { currentValue.Clear(); return(value(item, state)); }, closure); #if WPF placementTarget.LocationChanged += closure.Handle; #elif WINDOWS_PHONE var page = placementTarget as PhoneApplicationFrame; if (page != null) { page.OrientationChanged += closure.Handle; } #endif placementTarget.SizeChanged += closure.Handle; var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(duration) }; timer.Tick += (sender, args) => TimerCallback(sender, closure); closure.Timer = timer; BeginOpenAnimation(popup, timer.Start); return(closure.Clear); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public override void Dispose() { if (_closure != null) _closure.Unsubscribe(true); _bindingSource.Dispose(); _bindingSource = null; ValueChanging = null; ValueChanged = null; _closure = null; base.Dispose(); }
/// <summary> /// Shows the specified message. /// </summary> protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource <object> tcs) { #if WPF var placementTarget = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive); #endif #if SILVERLIGHT var placementTarget = Application.Current.RootVisual as FrameworkElement; #endif #if NETFX_CORE || WINDOWSCOMMON var placementTarget = Window.Current; #endif if (placementTarget == null) { return; } var popups = ServiceProvider .AttachedValueProvider .GetOrAdd(placementTarget, PopupAttachedValuePath, (window, o) => new List <EventClosure>(), null); for (int index = 0; index < popups.Count; index++) { var eventClosure = popups[index]; if (duration >= eventClosure.Duration) { eventClosure.Clear(); index--; } } var popup = GetToastPopup(GetToastContentWrapper(GetToastContent(content))); #if WPF popup.PlacementTarget = placementTarget; #endif UpdatePosition(placementTarget, popup, position); popup.IsOpen = true; var closure = new EventClosure(popup, position, placementTarget) { TaskCompletionSource = tcs, Duration = duration, Closures = popups }; popups.Add(closure); #if WPF placementTarget.LocationChanged += closure.Handle; #elif WINDOWS_PHONE var page = placementTarget as PhoneApplicationFrame; if (page != null) { page.OrientationChanged += closure.Handle; } #endif placementTarget.SizeChanged += closure.Handle; var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(duration) }; timer.Tick += (sender, args) => TimerCallback(sender, closure); closure.Timer = timer; BeginOpenAnimation(popup, timer.Start); }