I am trying to make a notification popup that i want to show on some event. Every thing is going well but problem is i am unable to close that notification popup window as it still remain in Taskbar but get hide after few seconds of show. Any help will be greatly appreciated.
xaml file as follow:
<Window
x:Class="SQLExample.NotificationWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Notification Popup" Width="300" SizeToContent="Height"
WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Grid RenderTransformOrigin="0,1" x:Name="NotificationWindowsss">
<!-- Notification area -->
<Border BorderThickness="1" Background="White" BorderBrush="Black" CornerRadius="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="4*"/>
<RowDefinition Height="7"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Border CornerRadius="0,0,0,0" Background="SkyBlue">
<Grid>
<Button HorizontalAlignment="Right" Margin="5,5,5,5" Click="Button_Click" Grid.Row="0" Height="15" Width="15" Foreground="White">
<Button.Template>
<ControlTemplate>
<Grid>
<Ellipse>
<Ellipse.Fill>
<ImageBrush ImageSource="Images\Close-icon.png"/>
</Ellipse.Fill>
</Ellipse>
<ContentPresenter Content="x" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
<TextBlock TextWrapping="Wrap" Margin="10" Grid.Row="0" HorizontalAlignment="Left">
<Bold>Notification data</Bold>
</TextBlock>
</Grid>
</Border>
</Grid>
<StackPanel Margin="10" Grid.Row="1">
<TextBlock TextWrapping="Wrap">
Something just happened and you are being notified of it.
</TextBlock>
</StackPanel>
<Grid Grid.Row="2" Background="SkyBlue"/>
</Grid>
</Border>
<!-- Animation -->
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0:0:7" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Grid.Triggers>
<Grid.RenderTransform>
<ScaleTransform ScaleY="1" />
</Grid.RenderTransform>
</Grid>
</Window>
and xaml.cs is here.
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.Threading;
namespace SQLExample
{
public partial class NotificationWindow : Window
{
public NotificationWindow()
{
InitializeComponent();
Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
{
//var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
var workingArea = System.Windows.SystemParameters.WorkArea;
var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom));
this.Left = corner.X - this.ActualWidth-10;
this.Top = corner.Y - this.ActualHeight;
}));
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Thing I want to do is when notification popup window disappear or technical sense get 'Opacity' equal to zero then it should close itself and I was trying to do it through triggers but couldn't get on solution. Guide me how can I do this or other easy way to do it.
Thank you in advance.