<
Window
x:Class
=
"MyWPFApp.MainWindow"
xmlns
=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
=
"http://schemas.microsoft.com/winfx/2006/xaml"
Title
=
"MainWindow"
Height
=
"70"
Width
=
"250"
Loaded
=
"Window_Loaded"
>
<
Grid
>
<
TextBlock
Height
=
"36"
HorizontalAlignment
=
"Left"
Name
=
"gc"
Text
=
"不问你是谁只是沉醉!"
VerticalAlignment
=
"Top"
Width
=
"230"
FontSize
=
"24"
>
<
TextBlock.Foreground
>
<
LinearGradientBrush
>
<
GradientStop
Color
=
"Green"
></
GradientStop
>
<
GradientStop
x:Name
=
"gcc1"
Color
=
"Green"
Offset
=
"0.3"
></
GradientStop
>
<
GradientStop
x:Name
=
"gcc2"
Color
=
"Blue"
Offset
=
"0.3"
></
GradientStop
>
<
GradientStop
Color
=
"Blue"
Offset
=
"1"
></
GradientStop
>
</
LinearGradientBrush
>
</
TextBlock.Foreground
>
</
TextBlock
>
</
Grid
>
</
Window
>
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
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
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.Navigation;
using
System.Windows.Shapes;
namespace
MyWPFApp
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
}
private
void
Window_Loaded(
object
sender, RoutedEventArgs e)
{
System.Timers.Timer t =
new
System.Timers.Timer(200);
//实例化Timer类,设置间隔时间为200毫秒;
t.Elapsed +=
new
System.Timers.ElapsedEventHandler(theout);
//到达时间的时候执行事件;
t.AutoReset =
true
;
//设置是执行一次(false)还是一直执行(true);
t.Enabled =
true
;
//是否执行System.Timers.Timer.Elapsed事件; ,调用start()方法也可以将其设置为true
}
public
void
theout(
object
source, System.Timers.ElapsedEventArgs e)
{
}
}
}
|
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
|
public
void
theout(
object
source, System.Timers.ElapsedEventArgs e)
{
this
.gcc1.Dispatcher.Invoke(
new
Action(
delegate
{
if
(
this
.gcc1.Offset < 1)
{
this
.gcc1.Offset += 0.1;
}
else
{
this
.gcc1.Offset = 0;
}
}
)
);
this
.gcc2.Dispatcher.Invoke(
new
Action(
delegate
{
if
(
this
.gcc2.Offset < 1)
{
this
.gcc2.Offset += 0.1;
}
else
{
this
.gcc2.Offset = 0;
}
}
)
);
}
|