public static Storyboard CreateSimpleDoubleAnimationStoryboard(UIElement targetElement, double durationMilliseconds, double?from, double?to, string propertyPath) { DoubleAnimation myDoubleAnimation = StoryboardFactory.CreateDoubleAnimation(targetElement, durationMilliseconds, from, to, propertyPath); Storyboard sb = new Storyboard(); sb.Children.Add(myDoubleAnimation); return(sb); }
public static bool ShowDialog(this FrameworkElement uiContent, Point?dialogPos, bool isModelDialog = true, bool canCancel = true, Action closeDialogCallback = null) { if (maskPanel == null) { maskPanel = new Canvas(); maskPanel.SetZIndex(10000); maskPanel.HorizontalAlignment = HorizontalAlignment.Stretch; maskPanel.VerticalAlignment = VerticalAlignment.Stretch; Grid.SetColumnSpan(maskPanel, 1000); Grid.SetRowSpan(maskPanel, 1000); maskPanel.Background = new SolidColorBrush(Color.FromArgb(150, 0, 0, 0)); showSb = StoryboardFactory.CreateSimpleDoubleAnimationStoryboard(maskPanel, 500, 0.2, 1.0, StoryboardFactory.Opacity); closeSb = StoryboardFactory.CreateSimpleDoubleAnimationStoryboard(maskPanel, 500, 1.0, 0.2, StoryboardFactory.Opacity); closeSb.Completed += new EventHandler(closeSb_Completed); showSb.Completed += new EventHandler(showSb_Completed); } if (maskPanel.Children.Count == 0) { if (Application.Current != null) { Panel root = Application.Current.MainWindow.Content as Panel; if (root != null) { if (isModelDialog) { maskPanel.HorizontalAlignment = HorizontalAlignment.Stretch; maskPanel.VerticalAlignment = VerticalAlignment.Stretch; if (canCancel) { eventHandel = delegate(object sender, TouchEventArgs ex) { FrameworkElement source = ex.Source as FrameworkElement; bool result = source.IsChildOfTarget(uiContent); if (result == false && uiContent != source) { bool closeResult = uiContent.CloseDialog(); if (closeResult && closeDialogCallback != null) { closeDialogCallback(); } } }; maskPanel.TouchDown += eventHandel; } } else { maskPanel.HorizontalAlignment = HorizontalAlignment.Center; maskPanel.VerticalAlignment = VerticalAlignment.Center; } if (dialogPos.HasValue) { Canvas.SetLeft(uiContent, dialogPos.Value.X); Canvas.SetTop(uiContent, dialogPos.Value.Y); } else { if (uiContent.IsLoaded) { Canvas.SetLeft(uiContent, (Application.Current.MainWindow.ActualWidth - uiContent.RenderSize.Width) / 2); Canvas.SetTop(uiContent, (Application.Current.MainWindow.ActualHeight - uiContent.RenderSize.Height) / 2); } else { uiContent.Loaded += (sender, ex) => { Canvas.SetLeft(uiContent, (Application.Current.MainWindow.ActualWidth - uiContent.RenderSize.Width) / 2); Canvas.SetTop(uiContent, (Application.Current.MainWindow.ActualHeight - uiContent.RenderSize.Height) / 2); }; } } maskPanel.Children.Add(uiContent); root.Children.Add(maskPanel); maskPanel.IsHitTestVisible = false; showSb.Begin(); return(true); } } } return(false); }