I am trying to make a WPF application that can slide from the edge of the right-most screen when you hit a button (like F8). This will be similar to the Windows Notification bar in windows 10.
I am struggling finding ways to make something similar. Any help would be greatly appreciated!
I am able to make a window with a given height, width, and make it stick to the right side of screen and top as such:
public MainWindow()
{
InitializeComponent();
Width = 300;
Height = System.Windows.SystemParameters.WorkArea.Height;
Left = System.Windows.SystemParameters.WorkArea.Width - Width;
Top = 0;
}
You could override the OnPreviewKeyDown
method of the window and use a DoubleAnimation
to animate the Left
property. Something like this:
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.Key == Key.F8)
{
double distanceToSlide = 100;
DoubleAnimation doubleAnimation = new DoubleAnimation()
{
From = Left,
To = Left - distanceToSlide,
Duration = new Duration(TimeSpan.FromSeconds(1))
};
this.BeginAnimation(Window.LeftProperty, doubleAnimation);
}
}
The above example slides the window 100 DIP to the left during a second. You can change the properties of DoubleAnimation
according to your requirements obviously.