예제 #1
0
        private static void ChangeOwner(Toastinet toast, FrameworkElement parent)
        {
            // Remove toast from parent
            if (parent != null)
            {
                IEnumerable <UIElement> parentContainer = VisualTreeHelperUtil.GetControlsDecendant <Grid>(parent);
                var grid = parentContainer.FirstOrDefault() as System.Windows.Controls.Grid;
                if (grid != null)
                {
                    grid.Children.Remove(toast);
                }
                else
                {
                    var panel = parentContainer.FirstOrDefault() as StackPanel;
                    if (panel != null)
                    {
                        panel.Children.Remove(toast);
                    }
                }
            }

            // Set ZIndex of the dynamic toast
            Canvas.SetZIndex(toast, 99999);

            // Try to find First Grid
            IEnumerable <UIElement> container = VisualTreeHelperUtil.GetControlsDecendant <Grid>(toast.Owner);

            if (container.FirstOrDefault() != null)
            {
                ((Grid)container.First()).Children.Insert(0, toast);
            }
            else
            {
                //no grid, is there a stackpanel
                container = VisualTreeHelperUtil.GetControlsDecendant <StackPanel>(toast.Owner);
                if (container.FirstOrDefault() != null)
                {
                    ((Grid)container.First()).Children.Insert(0, toast);
                }
                else
                {
                    throw new Exception("Unable to find window container of type Grid or StackPanel");
                }
            }

            VisualStateManager.GoToState(toast, toast.GetValidAnimation() + "Opened", true);
            VisualStateManager.GoToState(toast, toast.GetValidAnimation() + "Closed", true);
        }
예제 #2
0
        private static void ChangeOwner(Toastinet toast, FrameworkElement parent)
        {
            // Remove toast from parent
            if (parent != null)
            {
                IEnumerable<UIElement> parentContainer = VisualTreeHelperUtil.GetControlsDecendant<Grid>(parent);
                var grid = parentContainer.FirstOrDefault() as System.Windows.Controls.Grid;
                if (grid != null)
                    grid.Children.Remove(toast);
                else
                {
                    var panel = parentContainer.FirstOrDefault() as StackPanel;
                    if (panel != null)
                        panel.Children.Remove(toast);
                }
            }

            // Set ZIndex of the dynamic toast
            Canvas.SetZIndex(toast, 99999);

            // Try to find First Grid
            IEnumerable<UIElement> container = VisualTreeHelperUtil.GetControlsDecendant<Grid>(toast.Owner);
            if (container.FirstOrDefault() != null)
            {
                ((Grid)container.First()).Children.Insert(0, toast);
            }
            else
            {
                //no grid, is there a stackpanel
                container = VisualTreeHelperUtil.GetControlsDecendant<StackPanel>(toast.Owner);
                if (container.FirstOrDefault() != null)
                {
                    ((Grid)container.First()).Children.Insert(0, toast);
                }
                else
                {
                    throw new Exception("Unable to find window container of type Grid or StackPanel");
                }
            }

            VisualStateManager.GoToState(toast, toast.GetValidAnimation() + "Opened", true);
            VisualStateManager.GoToState(toast, toast.GetValidAnimation() + "Closed", true);
        }
예제 #3
0
        private void OnRuntime(object sender, EventArgs e)
        {
            if (globalToast == null)
            {
                // Initialize a new toast
                globalToast = new Toastinet
                {
                    Owner = sender as FrameworkElement,
                    Name = "Toast5",
                    Duration = 1,
                    Title = "Toastinet Runtime",
                    AnimationType = AnimationType.Vertical,
                    VerticalAlignment = VerticalAlignment.Top,
                    Message = ""
                };
                //globalToast.Closed += (a, b) =>
                //{
                //    (globalToast.Owner as Window).Close();
                //    (globalToast.Owner as Window).ContentRendered -= OnRuntime;
                //};
            }

            globalToast.Owner = sender as FrameworkElement;
            globalToast.Show("test");
        }