using System using System Collections Generic using System Text using

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Interop;
using System.Runtime.InteropServices;
using System.Windows.Media;
using System.Collections;
using System.Windows.Media.Animation;
namespace MyStyle
{
internal static class LocalExtensions
{
public static void ForWindowFromTemplate(this object templateFrameworkElement, Action<Window> action)
{
Window window = ((FrameworkElement)templateFrameworkElement).TemplatedParent as Window;
if (window != null) action(window);
}
public static IntPtr GetWindowHandle(this Window window)
{
WindowInteropHelper helper = new WindowInteropHelper(window);
return helper.Handle;
}
}
public partial class WindowStyle
{
void IconMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount > 1)
sender.ForWindowFromTemplate(w => SystemCommands.CloseWindow(w));
}
void IconMouseUp(object sender, MouseButtonEventArgs e)
{
var element = sender as FrameworkElement;
var point = element.PointToScreen(new Point(element.ActualWidth / 2, element.ActualHeight));
sender.ForWindowFromTemplate(w => SystemCommands.ShowSystemMenu(w, point));
}
void WindowLoaded(object sender, RoutedEventArgs e)
{
((Window)sender).StateChanged += WindowStateChanged;
}
void WindowStateChanged(object sender, EventArgs e)
{
var w = ((Window)sender);
var handle = w.GetWindowHandle();
var containerBorder = (Border)w.Template.FindName("PART_Container", w);
if (w.WindowState != WindowState.Maximized) {
containerBorder.Padding = new Thickness(7, 7, 7, 5);
}
}
void CloseButtonClick(object sender, RoutedEventArgs e)
{
sender.ForWindowFromTemplate(w => SystemCommands.CloseWindow(w));
}
void MinButtonClick(object sender, RoutedEventArgs e)
{
sender.ForWindowFromTemplate(w => SystemCommands.MinimizeWindow(w));
}
void MaxButtonClick(object sender, RoutedEventArgs e)
{
sender.ForWindowFromTemplate(w =>
{
if (w.WindowState == WindowState.Maximized) SystemCommands.RestoreWindow(w);
else SystemCommands.MaximizeWindow(w);
});
}
private AnimationClock controllerClock1 = null;
private Slider slider1;
private Button targetButton1;
public void buttonClick1(object sender, RoutedEventArgs e)
{
if (controllerClock1 == null)
{
DoubleAnimation widthAnimation = new DoubleAnimation(
1,
100,
new Duration(TimeSpan.FromSeconds(1))
);
widthAnimation.AutoReverse = true;
widthAnimation.RepeatBehavior = RepeatBehavior.Forever;
controllerClock1 = widthAnimation.CreateClock();
Button btnTarget = (Button)e.Source;
targetButton1 = btnTarget;
StackPanel st = (StackPanel)((StackPanel)btnTarget.Parent).Parent;
Rectangle animatedRect = (Rectangle)st.FindName("rect1");
animatedRect.ApplyAnimationClock(FrameworkElement.WidthProperty, controllerClock1);
controllerClock1.Controller.Begin();
btnTarget.Content = "Остановить анимацию ширины";
slider1 = (Slider)st.FindName("trackBar1");
slider1.Visibility = Visibility.Visible;
slider1.ValueChanged += Slider1AnimationChanged;
}
else
{
if (controllerClock1.IsPaused)
{
controllerClock1.Controller.Resume();
targetButton1.Content = "Остановить анимацию";
} else {
controllerClock1.Controller.Pause();
targetButton1.Content = "Продолжить анимацию";
}
}
}
private void Slider1AnimationChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
controllerClock1.Controller.Pause();
targetButton1.Content = "Продолжить анимацию";
Slider slider = (Slider)sender;
double value = slider1.Value;
TimeSpan seekAmount = TimeSpan.FromSeconds(value);
TimeSeekOrigin selectedOrigin = TimeSeekOrigin.BeginTime;
controllerClock1.Controller.Seek(seekAmount, selectedOrigin);
}
}
}