view 代码如下:
1
2
3
4
5
6
7
10
11
12
13
14
15
16 Storyboard.TargetProperty="Width"
17 From="20" To="200" Duration="0:0:2"
18 AutoReverse="True" RepeatBehavior="Forever"/>
19
20 Storyboard.TargetProperty="Height"
21 From="20" To="200" Duration="0:0:2"
22 AutoReverse="True" RepeatBehavior="Forever"/>
23
24
25
26
27
28
code behind 如下:
1 private readonly string _strPath;
2 private List<string> _pathList;
3 private int _index;
4
5 public Window2()
6 {
7 InitializeComponent();
8 _strPath &#61; Directory.GetCurrentDirectory();
9 _pathList &#61; new List<string>();
10 this.Loaded &#43;&#61; new RoutedEventHandler(Window2_Loaded);
11 }
12
13 void Window2_Loaded(object sender, RoutedEventArgs e)
14 {
15 ShowFirstImg();
16 }
17
18 private void ShowFirstImg()
19 {
20 string[] str &#61; Directory.GetDirectories("Imgs");
21 string[] imgStr &#61; Directory.GetFiles(str[0]);
22 for (int nI &#61; 0; nI
24 string fileName &#61; imgStr[nI].ToLower();
25 if (fileName.EndsWith(".bmp", StringComparison.CurrentCulture))
26 {
27 _pathList.Add(imgStr[nI]);
28 }
29 else if (fileName.EndsWith(".gif", StringComparison.CurrentCulture))
30 {
31 _pathList.Add(imgStr[nI]);
32 }
33 else if (fileName.EndsWith(".png", StringComparison.CurrentCulture))
34 {
35 _pathList.Add(imgStr[nI]);
36 }
37 else if (fileName.EndsWith(".jpg", StringComparison.CurrentCulture))
38 {
39 _pathList.Add(imgStr[nI]);
40 }
41 else
42 {
43 continue;
44 }
45 }
46
47 _index &#61; 0;
48 string firstImgPath &#61; _strPath &#43; "\\" &#43; _pathList[_index];
49 MyImage.Source &#61; new BitmapImage(new Uri(firstImgPath));
50 }
51
52 private void BtnFlip_Click(object sender, RoutedEventArgs e)
53 {
54 if (Object.ReferenceEquals(sender, BtnPrevious))
55 {
56 if (_index &#61;&#61; 0)
57 {
58 _index &#61; _pathList.Count - 1;
59 }
60 else
61 {
62 _index--;
63 }
64 string strAll &#61; _strPath &#43; "\\" &#43; _pathList[_index];
65 MyImage.Source &#61; new BitmapImage(new Uri(strAll));
66 }
67 else if (Object.ReferenceEquals(sender, BtnNext))
68 {
69 if (_index &#61;&#61; _pathList.Count - 1)
70 {
71 _index &#61; 0;
72 }
73 else
74 {
75 _index&#43;&#43;;
76 }
77 string strAll &#61; _strPath &#43; "\\" &#43; _pathList[_index];
78 MyImage.Source &#61; new BitmapImage(new Uri(strAll));
79 }
80 else
81 {
82 }
83 }