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.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace TweetBoard.GUI.Controls.Module
{
public class NotificationModule : Border
{
private StackPanel _layoutRoot
{
get;
set;
}
private Border _title
{
get;
set;
}
private StackPanel _content
{
get;
set;
}
private Border _image
{
get;
set;
}
private TextBlock _text
{
get;
set;
}
public String Title
{
set
{
(this._title.Child as TextBlock).Text = value;
}
}
public String Text
{
set
{
this._text.Text = value;
}
}
public String Image
{
set
{
this._image.Background = new ImageBrush(new BitmapImage(new Uri(value)));
}
}
public NotificationModule()
{
this.Background = new BrushConverter().ConvertFromString("#FFFFFF") as SolidColorBrush;
this.BorderBrush = new BrushConverter().ConvertFromString("#EFEFEF") as SolidColorBrush;
this.BorderThickness = new Thickness(1);
this.Margin = new Thickness(20, 20, 20, 0);
this.Width = 360;
this.MinHeight = 100;
this._layoutRoot = new StackPanel();
this._layoutRoot.Orientation = Orientation.Vertical;
this._layoutRoot.HorizontalAlignment = HorizontalAlignment.Stretch;
this._layoutRoot.VerticalAlignment = VerticalAlignment.Stretch;
this.Child = this._layoutRoot;
this._title = new Border();
this._title.Background = new BrushConverter().ConvertFromString("#FAFAFA") as SolidColorBrush;
this._title.BorderBrush = new BrushConverter().ConvertFromString("#EFEFEF") as SolidColorBrush;
this._title.BorderThickness = new Thickness(0, 0, 0, 1);
this._title.Padding = new Thickness(13);
this._layoutRoot.Children.Add(this._title);
this._title.Child = new TextBlock()
{
Text = "Notificatie",
FontSize = 20,
FontFamily = new FontFamily(new Uri("pack://application:,,,/GUI/Resources/Fonts/"), "#Lato Light"),
Foreground = new BrushConverter().ConvertFromString("#7A7A7A") as SolidColorBrush
};
this._content = new StackPanel();
this._content.Orientation = Orientation.Horizontal;
this._content.HorizontalAlignment = HorizontalAlignment.Stretch;
this._content.VerticalAlignment = VerticalAlignment.Top;
this._layoutRoot.Children.Add(this._content);
this._image = new Border();
this._image.Background = Brushes.DeepSkyBlue;
this._image.BorderBrush = new BrushConverter().ConvertFromString("#EFEFEF") as SolidColorBrush;
this._image.BorderThickness = new Thickness(1);
this._image.Height = 75;
this._image.Width = 75;
this._image.Margin = new Thickness(10);
this._image.VerticalAlignment = VerticalAlignment.Top;
this._content.Children.Add(this._image);
this._text = new TextBlock();
this._text.Width = 240;
this._text.Margin = new Thickness(0, 10, 10, 10);
this._text.FontFamily = new FontFamily(new Uri("pack://application:,,,/GUI/Resources/Fonts/"), "#Lato Light");
this._text.FontSize = 16;
this._text.Foreground = new BrushConverter().ConvertFromString("#7A7A7A") as SolidColorBrush;
this._text.TextAlignment = TextAlignment.Left;
this._text.TextWrapping = TextWrapping.Wrap;
this._text.VerticalAlignment = VerticalAlignment.Top;
this._content.Children.Add(this._text);
this.MouseDown += (Sender, Args) =>
{
this.Hide();
};
this.Loaded += (Sender, Args) =>
{
this.Show();
};
this.PrepareHide();
}
private async void PrepareHide()
{
await Task.Delay(5000);
this.Hide();
}
public void Show()
{
Duration d = new Duration(new TimeSpan(0, 0, 0, 0, 400));
ThicknessAnimation tAni = new ThicknessAnimation(new Thickness(this.ActualWidth, 20, (0 - this.ActualWidth), 0), this.Margin, d);
DoubleAnimation oAni = new DoubleAnimation(0, 1, d);
Storyboard s = new Storyboard();
s.Children.Add(tAni);
s.Children.Add(oAni);
Storyboard.SetTarget(tAni, this);
Storyboard.SetTargetProperty(tAni, new PropertyPath(MarginProperty));
Storyboard.SetTarget(oAni, this);
Storyboard.SetTargetProperty(oAni, new PropertyPath(OpacityProperty));
s.Begin();
}
public void Hide()
{
Duration d = new Duration(new TimeSpan(0, 0, 0, 0, 400));
ThicknessAnimation tAni = new ThicknessAnimation(this.Margin, new Thickness(20, (0 - this.ActualHeight), 20, 0), d);
DoubleAnimation oAni = new DoubleAnimation(1, 0, d);
Storyboard s = new Storyboard();
s.Children.Add(tAni);
s.Children.Add(oAni);
Storyboard.SetTarget(tAni, this);
Storyboard.SetTargetProperty(tAni, new PropertyPath(MarginProperty));
Storyboard.SetTarget(oAni, this);
Storyboard.SetTargetProperty(oAni, new PropertyPath(OpacityProperty));
s.Begin();
}
}
}