1.问题:最近手上有个项目,需要用到wpf, wpf没有silverlight的childwindow, 这样弹窗口不是很方便
2.解决办法:整合了一下网上意见,得到解决办法如下:
public static class ChildWindowBehaviorRegist
{
public static void Show(this FrameworkElement control)
{
Grid grid = GetRootGrid(control );
RootAndMask ram = GetRootAndMask(control);
if (grid != null && ram !=null )
{
DoubleAnimation opacityAnimation = new DoubleAnimation(0.5, new Duration(TimeSpan.FromSeconds(0.5)));
Storyboard opacityBoard = new Storyboard();
opacityBoard.Children.Add(opacityAnimation);
Storyboard.SetTarget(opacityAnimation, ram.MaskRectangle );
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(Opacity)"));
opacityBoard.Completed += delegate
{
ScaleTransform scaleTransform = new ScaleTransform(0.0, 0.0, control.Width / 2.0, control.Height / 2.0);
control.RenderTransform = scaleTransform;
grid.Children.Add(control);
Storyboard scaleBoard = ne