Dictionary.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Storyboard x:Key="StoryboardOpacityDown">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3" Value="0.4"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="StoryboardOpacityUp">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Style x:Key="SubWindowStyle" TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="ShowInTaskbar" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Border CornerRadius="10" Background="Crimson">
<ContentPresenter/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
MainWindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
WindowState="Maximized">
<Grid>
<Border Background="LightBlue">
<StackPanel Orientation="Horizontal">
<Border Height="300" Width="300" Background="White" HorizontalAlignment="Left"/>
<Button Height="30" Width="80" Content="Nowe okno" HorizontalAlignment="Left" Click="Button_Click"/>
</StackPanel>
</Border>
</Grid>
</Window>
MainWindow.xaml.cs
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
((Storyboard)FindResource("StoryboardOpacityDown")).Begin(this);
ChildWindow childWindow = new ChildWindow();
childWindow.ShowDialog();
((Storyboard)FindResource("StoryboardOpacityUp")).Begin(this);
}
}
}
ChildWindow.xaml
<Window x:Class="WpfApplication1.ChildWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChildWindow" Height="300" Width="300"
MouseLeftButtonDown="DragWindow_MouseLeftButtonDown"
Style="{DynamicResource SubWindowStyle}">
<Grid>
<StackPanel Orientation="Vertical">
<Button Height="30" Width="80" Content="Nowe okno" HorizontalAlignment="Left" Margin="0,20,0,0" Click="Button_Click"/>
<Button Height="30" Width="80" Content="Zamknij" HorizontalAlignment="Left" Margin="0,20,0,0" Click="Button2_Click"/>
</StackPanel>
</Grid>
</Window>
ChildWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for ChildWindow.xaml
/// </summary>
public partial class ChildWindow : Window
{
public ChildWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
((Storyboard)FindResource("StoryboardOpacityDown")).Begin(this);
MessageBox.Show("Nowe okno");
((Storyboard)FindResource("StoryboardOpacityUp")).Begin(this);
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void DragWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
}
}