Improve notification appearance sync
authorThomas
Tue, 30 Apr 2019 16:47:40 +0200
branchsync
changeset 2624c28e59231408
parent 2623 d0c935a45a22
child 2625 d30e7f635ac7
Improve notification appearance
UI/Notification.xaml
UI/Notification.xaml.cs
     1.1 --- a/UI/Notification.xaml	Tue Apr 30 12:42:30 2019 +0200
     1.2 +++ b/UI/Notification.xaml	Tue Apr 30 16:47:40 2019 +0200
     1.3 @@ -1,22 +1,51 @@
     1.4 -<Window x:Class="pEp.UI.Notification"
     1.5 -            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     1.6 -            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     1.7 -            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     1.8 -            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     1.9 -            xmlns:local="clr-namespace:pEp.UI"
    1.10 -            mc:Ignorable="d" 
    1.11 -            AllowsTransparency="True"
    1.12 -            Background="Transparent"
    1.13 -            WindowStyle="None"
    1.14 -            ShowInTaskbar="False"
    1.15 -            Height="100" Width="300">
    1.16 -    <Grid RenderTransformOrigin="0,1" >
    1.17 +<Window Name="NotificationWindow"
    1.18 +        x:Class="pEp.UI.Notification"
    1.19 +        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    1.20 +        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    1.21 +        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    1.22 +        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    1.23 +        xmlns:local="clr-namespace:pEp.UI"
    1.24 +        mc:Ignorable="d" 
    1.25 +        AllowsTransparency="True"
    1.26 +        Background="Transparent"
    1.27 +        WindowStyle="None"
    1.28 +        ShowInTaskbar="False"
    1.29 +        Topmost="True"
    1.30 +        Height="100" 
    1.31 +        Width="300">
    1.32 +
    1.33 +    <Grid RenderTransformOrigin="0,1">
    1.34  
    1.35          <!-- Notification area -->
    1.36 -        <Border BorderThickness="1" Background="Black" BorderBrush="Black">
    1.37 -            <StackPanel Margin="10">
    1.38 -                <TextBlock Foreground="White" FontWeight="DemiBold" Text="{Binding TitleText}" Margin="5,0,5,5"/>
    1.39 -                <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding NotificationText}" Margin="5,5,0,5"/>
    1.40 +        <Border BorderThickness="1" 
    1.41 +                Background="Black" 
    1.42 +                BorderBrush="Black">
    1.43 +            <StackPanel Margin="5">
    1.44 +                <TextBlock Foreground="White"
    1.45 +                           Text="&#10005;"
    1.46 +                           FontWeight="Light"
    1.47 +                           HorizontalAlignment="Right" 
    1.48 +                           MouseUp="TextBlock_MouseUp"
    1.49 +                           Padding="3">
    1.50 +                    <TextBlock.Style>
    1.51 +                        <Style>
    1.52 +                            <Style.Triggers>
    1.53 +                                <Trigger Property="TextBlock.IsMouseOver" Value="True">
    1.54 +                                    <Setter Property="TextBlock.Background" Value="#666666"/>
    1.55 +                                </Trigger>
    1.56 +
    1.57 +                            </Style.Triggers>
    1.58 +                        </Style>
    1.59 +                    </TextBlock.Style>
    1.60 +                </TextBlock>
    1.61 +                <TextBlock Foreground="White" 
    1.62 +                           FontWeight="DemiBold" 
    1.63 +                           Text="{Binding TitleText}" 
    1.64 +                           Margin="5,0,5,5"/>
    1.65 +                <TextBlock TextWrapping="Wrap" 
    1.66 +                           Foreground="White" 
    1.67 +                           Text="{Binding NotificationText}" 
    1.68 +                           Margin="5,5,0,5"/>
    1.69              </StackPanel>
    1.70          </Border>
    1.71  
    1.72 @@ -24,18 +53,41 @@
    1.73          <Grid.Triggers>
    1.74              <EventTrigger RoutedEvent="FrameworkElement.Loaded">
    1.75                  <BeginStoryboard>
    1.76 -                    <Storyboard Completed="Storyboard_Completed">
    1.77 -                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
    1.78 -                            <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
    1.79 -                            <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
    1.80 -                        </DoubleAnimationUsingKeyFrames>
    1.81 -                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
    1.82 -                            <SplineDoubleKeyFrame KeyTime="0:0:4" Value="1"/>
    1.83 -                            <SplineDoubleKeyFrame KeyTime="0:0:6" Value="0"/>
    1.84 -                        </DoubleAnimationUsingKeyFrames>
    1.85 +                    <Storyboard>
    1.86 +                        <DoubleAnimation Storyboard.TargetName="NotificationWindow"
    1.87 +                                         Storyboard.TargetProperty="Left"
    1.88 +                                         From="{Binding AnimationStartX}" 
    1.89 +                                         To="{Binding AnimationEndX}"  
    1.90 +                                         Duration="0:0:0.5"                                        
    1.91 +                                         />
    1.92 +                        <DoubleAnimation Name="OpacityAnimation"
    1.93 +                                         Storyboard.TargetName="NotificationWindow"
    1.94 +                                         Storyboard.TargetProperty="Opacity"
    1.95 +                                         From="1"
    1.96 +                                         To="0"
    1.97 +                                         BeginTime="0:0:2"
    1.98 +                                         Duration="0:0:4"/>
    1.99                      </Storyboard>
   1.100                  </BeginStoryboard>
   1.101              </EventTrigger>
   1.102 +            <EventTrigger RoutedEvent="Window.MouseEnter">
   1.103 +                <EventTrigger.Actions>
   1.104 +                    <BeginStoryboard>
   1.105 +                        <Storyboard BeginTime="00:00:00" RepeatBehavior="Forever"  AutoReverse="True" Storyboard.TargetName="NotificationWindow" Storyboard.TargetProperty="Opacity">
   1.106 +                            <DoubleAnimation From="1" To="1" />
   1.107 +                        </Storyboard>
   1.108 +                    </BeginStoryboard>
   1.109 +                </EventTrigger.Actions>
   1.110 +            </EventTrigger>
   1.111 +            <EventTrigger RoutedEvent="Window.MouseLeave">
   1.112 +                <EventTrigger.Actions>
   1.113 +                    <BeginStoryboard>
   1.114 +                        <Storyboard BeginTime="00:00:00" RepeatBehavior="Forever"  AutoReverse="True" Storyboard.TargetName="NotificationWindow" Storyboard.TargetProperty="Opacity">
   1.115 +                            <DoubleAnimation From="1" To="0" Duration="0:0:4"/>
   1.116 +                        </Storyboard>
   1.117 +                    </BeginStoryboard>
   1.118 +                </EventTrigger.Actions>
   1.119 +            </EventTrigger>
   1.120          </Grid.Triggers>
   1.121  
   1.122          <Grid.RenderTransform>
     2.1 --- a/UI/Notification.xaml.cs	Tue Apr 30 12:42:30 2019 +0200
     2.2 +++ b/UI/Notification.xaml.cs	Tue Apr 30 16:47:40 2019 +0200
     2.3 @@ -21,23 +21,21 @@
     2.4      /// </summary>
     2.5      public partial class Notification : Window
     2.6      {
     2.7 +        private const double offset = 10;
     2.8          public string TitleText { get; private set; }
     2.9          public string NotificationText { get; private set; }
    2.10 +        public double AnimationStartX { get; private set; }
    2.11 +        public double AnimationEndX { get; private set; }
    2.12  
    2.13          public Notification()
    2.14          {
    2.15              InitializeComponent();
    2.16              this.DataContext = this;
    2.17  
    2.18 -            Dispatcher.BeginInvoke(new Action(() =>
    2.19 -            {
    2.20 -                var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
    2.21 -                var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
    2.22 -                var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom));
    2.23 -
    2.24 -                this.Left = corner.X - this.ActualWidth - 10;
    2.25 -                this.Top = corner.Y - this.ActualHeight - 10;
    2.26 -            }));
    2.27 +            var desktopWorkingArea = SystemParameters.WorkArea;
    2.28 +            this.AnimationStartX = desktopWorkingArea.Right;
    2.29 +            this.AnimationEndX = desktopWorkingArea.Right - this.Width - Notification.offset;
    2.30 +            this.Top = desktopWorkingArea.Bottom - this.Height - Notification.offset;
    2.31          }
    2.32  
    2.33          public Notification(string title, string text) : this()
    2.34 @@ -50,5 +48,10 @@
    2.35          {            
    2.36              this.Close();
    2.37          }
    2.38 +
    2.39 +        private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)
    2.40 +        {
    2.41 +            this.Close();
    2.42 +        }
    2.43      }
    2.44  }