├── .gitattributes
├── .gitignore
├── README.md
├── WPF样式收集.sln
└── WPF样式收集
├── App.config
├── App.xaml
├── App.xaml.cs
├── Global.cs
├── LeftMenuInfo.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Pages
├── 3D切图式过渡效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── My3DCubeControl.xaml
│ ├── My3DCubeControl.xaml.cs
│ ├── My3DImageControl.xaml
│ ├── My3DImageControl.xaml.cs
│ ├── MyRollControl.xaml
│ └── MyRollControl.xaml.cs
├── 3D发光立方体效果
│ ├── Index.xaml
│ └── Index.xaml.cs
├── 3D立方体波浪墙效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── Particle.cs
│ └── ParticleSystem.cs
├── 3D粒子波浪效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── Particle.cs
│ └── ParticleSystem.cs
├── 3D翻转
│ ├── Index.xaml
│ └── Index.xaml.cs
├── DNA螺旋粒子动画
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── Particle.cs
│ └── ParticleSystem.cs
├── Loading
│ ├── EllipseCircleAnimation.cs
│ ├── EllipsePendulum.xaml
│ ├── EllipsePendulum.xaml.cs
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── LoadingCircle.xaml
│ ├── LoadingCircle.xaml.cs
│ ├── LoadingLeft2Right.xaml
│ ├── LoadingLeft2Right.xaml.cs
│ ├── LoadingPendulum.xaml
│ ├── LoadingPendulum.xaml.cs
│ ├── LoadingWave.xaml
│ └── LoadingWave.xaml.cs
├── Welcome.xaml
├── Welcome.xaml.cs
├── 图像倾斜视差效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyImageControl2D.xaml
│ └── MyImageControl2D.xaml.cs
├── 图片变换动画
│ ├── BlockAnimation.cs
│ ├── CircleAnimation.cs
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── InterlacedAnimation.cs
│ ├── RadialAnimation.cs
│ └── WaterFallAnimation.cs
├── 图片环形旋转轮动效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyCanvas.cs
│ ├── MyImageBox.xaml
│ └── MyImageBox.xaml.cs
├── 图片翻转切换特效
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyImageButton.xaml
│ └── MyImageButton.xaml.cs
├── 圆形警示效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── RingControl.xaml
│ └── RingControl.xaml.cs
├── 字体动画效果
│ ├── Ani1.xaml
│ ├── Ani1.xaml.cs
│ ├── Ani2.xaml
│ ├── Ani2.xaml.cs
│ ├── Ani3.xaml
│ ├── Ani3.xaml.cs
│ ├── Ani4.xaml
│ ├── Ani4.xaml.cs
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyImageControl.xaml
│ └── MyImageControl.xaml.cs
├── 悬停视差效果
│ ├── Index.xaml
│ └── Index.xaml.cs
├── 手风琴效果
│ ├── Expander.xaml
│ ├── Expander.xaml.cs
│ ├── ExpanderClass.cs
│ ├── GridLengthAnimation.cs
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyGridControl.xaml
│ └── MyGridControl.xaml.cs
├── 擦除效果
│ ├── Index.xaml
│ └── Index.xaml.cs
├── 水珠效果按钮组
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── UCWaterDropsButtonGroup.xaml
│ └── UCWaterDropsButtonGroup.xaml.cs
├── 水面波纹特效
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── Shader.fx
│ ├── WaterEffect.cs
│ └── water.ps
├── 聚光灯查看内容
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyImageBox.xaml
│ └── MyImageBox.xaml.cs
├── 背景动画
│ ├── BG1.xaml
│ ├── BG1.xaml.cs
│ ├── BG2.xaml
│ ├── BG2.xaml.cs
│ ├── BG3.xaml
│ ├── BG3.xaml.cs
│ ├── BG4.xaml
│ ├── BG4.xaml.cs
│ ├── BG5.xaml
│ ├── BG5.xaml.cs
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── Particle.cs
│ ├── ParticleSystem.cs
│ ├── StarInfo.cs
│ ├── Triangle.cs
│ └── TriangleSystem.cs
├── 菜单折叠效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ ├── MyButton.cs
│ ├── RoundMenuControl.xaml
│ └── RoundMenuControl.xaml.cs
└── 雪花效果
│ ├── Index.xaml
│ ├── Index.xaml.cs
│ └── MM.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── Resources
├── add.png
├── close.png
├── images1.jpg
├── images2.jpg
├── left.png
└── right.png
└── WPF样式收集.csproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WPFStyles
2 | WPF中比较特殊的窗体、页面样式动画收集,持续更新...
3 | 开发环境:
4 | VS2019
5 | .NETFramework472
6 |
7 | # 现有动画
8 | 3D立方体波浪墙效果
9 | 3D粒子波浪效果
10 | 3D翻转
11 | 图片变换动画
12 | 背景动画(5个)
13 | 雪花效果
14 | 聚光灯查看内容
15 |
16 | 3D切图式过渡效果
17 | Loading(4个)
18 | 擦除效果
19 | 菜单折叠效果
20 | 手风琴效果(2个)
21 | 水面波纹特效
22 | 图像倾斜视差效果
23 | 悬停视差效果
24 | 3D发光立方体效果
25 | 图片翻转切换特效
26 | 图片环形旋转轮动效果
27 | DNA螺旋粒子动画
28 | 水珠效果按钮组
29 | 字体动画效果(4个)
30 | 圆形警示效果
31 |
32 |
33 |
34 | # [效果图(知乎)](https://zhuanlan.zhihu.com/p/459008647)
--------------------------------------------------------------------------------
/WPF样式收集.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.32002.261
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF样式收集", "WPF样式收集\WPF样式收集.csproj", "{0853910B-7F9E-4BCD-A7F9-2B27419DFDCF}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CCABD762-D749-46C7-BADF-D427651FBDDA}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {0853910B-7F9E-4BCD-A7F9-2B27419DFDCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {0853910B-7F9E-4BCD-A7F9-2B27419DFDCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {0853910B-7F9E-4BCD-A7F9-2B27419DFDCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {0853910B-7F9E-4BCD-A7F9-2B27419DFDCF}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {424C1985-353A-4BFD-971B-F9AA94CF63F6}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/WPF样式收集/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/WPF样式收集/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
18 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/WPF样式收集/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WPF样式收集
10 | {
11 | ///
12 | /// App.xaml 的交互逻辑
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/WPF样式收集/Global.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WPF样式收集
8 | {
9 | ///
10 | /// 全局公用对象
11 | ///
12 | public class Global
13 | {
14 | public static MainWindow MainWindow;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/WPF样式收集/LeftMenuInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WPF样式收集
8 | {
9 | public class LeftMenuInfo
10 | {
11 | public string Name { get; set; }
12 | public string Url { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/WPF样式收集/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using System.Windows;
10 | using System.Windows.Controls;
11 | using System.Windows.Data;
12 | using System.Windows.Documents;
13 | using System.Windows.Input;
14 | using System.Windows.Media;
15 | using System.Windows.Media.Animation;
16 | using System.Windows.Media.Imaging;
17 | using System.Windows.Navigation;
18 | using System.Windows.Shapes;
19 | using System.Windows.Threading;
20 |
21 | namespace WPF样式收集
22 | {
23 | ///
24 | /// MainWindow.xaml 的交互逻辑
25 | ///
26 | public partial class MainWindow : Window
27 | {
28 | Storyboard stdStart;
29 |
30 | public MainWindow()
31 | {
32 | InitializeComponent();
33 |
34 | Global.MainWindow = this;
35 |
36 | stdStart = (Storyboard)this.Resources["start"];
37 | stdStart.Completed += (a, b) =>
38 | {
39 | this.root.Clip = null;
40 | };
41 | this.Loaded += mainWindow_Loaded;
42 | }
43 |
44 |
45 | private string indexPageName = "Index";//约定的页面名称
46 | ObservableCollection LeftMenus = new ObservableCollection();//左侧导航数据源
47 |
48 | private void mainWindow_Loaded(object sender, RoutedEventArgs e)
49 | {
50 | stdStart.Begin();
51 |
52 | lMenus.ItemsSource = LeftMenus;
53 | LoadPageMenus();
54 |
55 | }
56 |
57 | ///
58 | /// 加载导航
59 | ///
60 | private void LoadPageMenus()
61 | {
62 | LeftMenus.Clear();
63 | Assembly currAssembly = Assembly.GetExecutingAssembly();//获取当前程序集
64 | string pagesNamespace = $"{currAssembly.GetName().Name}.Pages";
65 | //查找所有页面的命名空间
66 | var pageNsps = (from t in currAssembly.GetTypes()
67 | where t.IsClass && t.Namespace != null
68 | && t.Namespace != pagesNamespace
69 | && t.Namespace.StartsWith(pagesNamespace)
70 | && !t.Namespace.StartsWith("<")
71 | select t.Namespace).GroupBy(c => c).ToList();
72 | foreach (var currPageNsp in pageNsps)//currPageNsp=当前的页面命名空间
73 | {
74 | var currPage = (from t in currAssembly.GetTypes()
75 | where t.IsClass && t.Namespace != null
76 | && t.Namespace == currPageNsp.Key
77 | select t.FullName).ToList();
78 | if (!currPage.Any(c => c.EndsWith(indexPageName)))
79 | {
80 | //没有Index文件 不参与
81 | continue;
82 | }
83 |
84 | //从上级文件夹中获取到文件夹名称
85 | string folderName = currPageNsp.Key.Substring(currPageNsp.Key.LastIndexOf('.') + 1);
86 | //如果文件名以_开头 去掉_
87 | if (folderName.StartsWith("_")) folderName = folderName.Substring(1);
88 |
89 | LeftMenus.Add(new LeftMenuInfo() { Name = folderName, Url = $"/Pages/{folderName}/{indexPageName}.xaml" });
90 | }
91 | }
92 |
93 | ///
94 | /// 切换导航
95 | ///
96 | ///
97 | ///
98 | private void lMenus_SelectionChanged(object sender, SelectionChangedEventArgs e)
99 | {
100 | if (lMenus.SelectedItem != null)//选中导航验证
101 | {
102 | LeftMenuInfo targetItem = lMenus.SelectedItem as LeftMenuInfo;//选中的导航
103 | if (!string.IsNullOrEmpty(targetItem.Url))//选中导航验证
104 | {
105 | SetBugs();
106 | string url = targetItem.Url;//获取URL
107 | mainFrame.Source = new Uri(url, UriKind.RelativeOrAbsolute);
108 | }
109 | }
110 | }
111 |
112 | private void btnClose_Click(object sender, MouseButtonEventArgs e)
113 | {
114 | if (MessageBox.Show("是否确认退出?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
115 | {
116 | Application.Current.Shutdown();
117 | }
118 | }
119 |
120 | private void bMove_MouseDown(object sender, MouseButtonEventArgs e)
121 | {
122 | if (e.LeftButton == MouseButtonState.Pressed)
123 | {
124 | this.DragMove();
125 | }
126 | }
127 |
128 | ///
129 | /// 设置Bug
130 | ///
131 | ///
132 | public void SetBugs(string bugStr = "")
133 | {
134 | #region 显示 隐藏
135 |
136 | if (string.IsNullOrEmpty(bugStr))
137 | {
138 | spBugs.Children.Clear();
139 | lblCurrPageBugs.Visibility = Visibility.Collapsed;
140 | spBugs.Visibility = Visibility.Collapsed;
141 | return;
142 | }
143 | else
144 | {
145 | if (lblCurrPageBugs.Visibility == Visibility.Collapsed) lblCurrPageBugs.Visibility = Visibility.Visible;
146 | if (spBugs.Visibility == Visibility.Collapsed) spBugs.Visibility = Visibility.Visible;
147 | }
148 |
149 | #endregion
150 |
151 | bugStr = $"{spBugs.Children.Count + 1}. {bugStr}";
152 | spBugs.Children.Add(new Label() { Content = bugStr, ToolTip = bugStr });
153 | lblCurrPageBugs.Content = $"Bug({spBugs.Children.Count})";
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages._3D切图式过渡效果
18 | {
19 | ///
20 | /// Index.xaml 的交互逻辑
21 | ///
22 | public partial class Index : Page
23 | {
24 | public Index()
25 | {
26 | InitializeComponent();
27 |
28 | Global.MainWindow.SetBugs("需要注意图片尺寸");
29 |
30 | List ls_adv_img = new List();
31 | List listAdv = GetUserImages(AppDomain.CurrentDomain.BaseDirectory+ "Images/3D切图式过渡效果");
32 | foreach (string a in listAdv)
33 | {
34 | BitmapImage img = new BitmapImage(new Uri(a));
35 | ls_adv_img.Add(img);
36 | }
37 | this.rollImg.ls_images = ls_adv_img;
38 | this.rollImg.Begin();
39 | }
40 |
41 | private void Page_Unloaded(object sender, RoutedEventArgs e)
42 | {
43 |
44 | }
45 |
46 | ///
47 | /// 获取当前用户的图片文件夹中的图片路径列表(不包含子文件夹)
48 | ///
49 | private List GetUserImages(string path)
50 | {
51 | List images = new List();
52 | DirectoryInfo dir = new DirectoryInfo(path);
53 | FileInfo[] files = GetPicFiles(path, "*.jpg,*.png,*.bmp,", SearchOption.TopDirectoryOnly);
54 |
55 | if (files != null)
56 | {
57 | foreach (FileInfo file in files)
58 | {
59 | images.Add(file.FullName);
60 | }
61 | }
62 | return images;
63 | }
64 |
65 | private FileInfo[] GetPicFiles(string picPath, string searchPattern, SearchOption searchOption)
66 | {
67 | List ltList = new List();
68 | DirectoryInfo dir = new DirectoryInfo(picPath);
69 | string[] sPattern = searchPattern.Replace(';', ',').Split(',');
70 | for (int i = 0; i < sPattern.Length; i++)
71 | {
72 | FileInfo[] files = null;
73 | try
74 | {
75 | files = dir.GetFiles(sPattern[i], searchOption);
76 | }
77 | catch
78 | {
79 | files = new FileInfo[] { };
80 | }
81 |
82 | ltList.AddRange(files);
83 | }
84 | return ltList.ToArray();
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/My3DCubeControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Animation;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages._3D切图式过渡效果
18 | {
19 | ///
20 | /// My3DCubeControl.xaml 的交互逻辑
21 | ///
22 | public partial class My3DCubeControl : UserControl
23 | {
24 | public static readonly DependencyProperty ImageFrontProperty = DependencyProperty.Register("ImageFront", typeof(BitmapSource), typeof(My3DCubeControl), new PropertyMetadata(null));
25 | public BitmapSource ImageFront
26 | {
27 | get { return (BitmapSource)GetValue(ImageFrontProperty); }
28 | set { SetValue(ImageFrontProperty, value); }
29 | }
30 |
31 | public static readonly DependencyProperty ImageBackProperty = DependencyProperty.Register("ImageBack", typeof(BitmapSource), typeof(My3DCubeControl), new PropertyMetadata(null));
32 | public BitmapSource ImageBack
33 | {
34 | get { return (BitmapSource)GetValue(ImageBackProperty); }
35 | set { SetValue(ImageBackProperty, value); }
36 | }
37 |
38 | public My3DCubeControl()
39 | {
40 | InitializeComponent();
41 | }
42 |
43 | ///
44 | /// 开启随机角度转动
45 | ///
46 | public void BeginRandomRotationAnimation()
47 | {
48 | Random rand = new Random();
49 | int c = Enum.GetValues(typeof(RotationDirection)).Length;
50 | int n = rand.Next(0, c);
51 | switch (n)
52 | {
53 | case (int)RotationDirection.Left:
54 | Storyboard leftStoryboard = this.FindResource("LeftStoryboard") as Storyboard;
55 | leftStoryboard.Begin();
56 | break;
57 | case (int)RotationDirection.Right:
58 | Storyboard rightStoryboard = this.FindResource("RightStoryboard") as Storyboard;
59 | rightStoryboard.Begin();
60 | break;
61 | case (int)RotationDirection.Upward:
62 | Storyboard upwardStoryboard = this.FindResource("UpwardStoryboard") as Storyboard;
63 | upwardStoryboard.Begin();
64 | break;
65 | case (int)RotationDirection.Downward:
66 | Storyboard downwardStoryboard = this.FindResource("DownwardStoryboard") as Storyboard;
67 | downwardStoryboard.Begin();
68 | break;
69 | }
70 | //放大缩小
71 | Storyboard zoomXStoryboard = this.FindResource("ZoomXStoryboard") as Storyboard;
72 | zoomXStoryboard.Begin();
73 | Storyboard zoomYStoryboard = this.FindResource("ZoomYStoryboard") as Storyboard;
74 | zoomYStoryboard.Begin();
75 | }
76 |
77 | //旋转方向
78 | public enum RotationDirection
79 | {
80 | Left,
81 | Right,
82 | Upward,
83 | Downward
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/My3DImageControl.xaml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/My3DImageControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages._3D切图式过渡效果
18 | {
19 | ///
20 | /// My3DImageControl.xaml 的交互逻辑
21 | ///
22 | public partial class My3DImageControl : UserControl
23 | {
24 | public BitmapImage FrontImage;//初始展示的图源
25 | public BitmapImage BackImage;//转动后展示的图源
26 | public bool isFinished = true;//动作是否结束
27 | private const int HorizontalCount = 4;//横向裁剪数量
28 | private const int VerticalCount = 4;//纵向裁剪数量
29 | private BitmapSource[,] FrontBitmap = new BitmapSource[HorizontalCount, VerticalCount];
30 | private BitmapSource[,] BackBitmap = new BitmapSource[HorizontalCount, VerticalCount];
31 |
32 | public My3DImageControl()
33 | {
34 | InitializeComponent();
35 | }
36 |
37 | ///
38 | /// 裁剪图片生成小3D立方体
39 | ///
40 | public void GetFlipImage()
41 | {
42 | this.mainCanvas.Children.Clear();
43 | if (this.FrontImage == null || this.BackImage == null)
44 | {
45 | isFinished = true;
46 | return;
47 | }
48 | //裁剪图片
49 | int partImgWidth = (int)(this.FrontImage.PixelWidth / HorizontalCount);
50 | int partImgHeight = (int)(this.FrontImage.PixelHeight / VerticalCount);
51 | int count = 0;
52 | for (int i = 0; i < HorizontalCount; i++)
53 | {
54 | for (int j = 0; j < VerticalCount; j++)
55 | {
56 | FrontBitmap[i, j] = GetPartImage(this.FrontImage, i * partImgWidth, j * partImgHeight, partImgWidth, partImgHeight);
57 | BackBitmap[i, j] = GetPartImage(this.BackImage, i * partImgWidth, j * partImgHeight, partImgWidth, partImgHeight);
58 | My3DCubeControl my3DCube = new My3DCubeControl();
59 | my3DCube.Width = partImgWidth;
60 | my3DCube.Height = partImgHeight;
61 | my3DCube.ImageFront = FrontBitmap[i, j];
62 | my3DCube.ImageBack = BackBitmap[i, j];
63 | Canvas.SetLeft(my3DCube, i * partImgWidth);
64 | Canvas.SetTop(my3DCube, j * partImgHeight);
65 | this.mainCanvas.Children.Add(my3DCube);
66 | count = count + i + j;
67 | }
68 | }
69 | isFinished = false;
70 | }
71 |
72 | ///
73 | /// 展示动画
74 | ///
75 | public void ShowAnimation()
76 | {
77 | List my3DCubesList = GetChildObjects(this.mainCanvas);
78 | foreach (var cube in my3DCubesList)
79 | {
80 | cube.BeginRandomRotationAnimation();
81 | Thread.Sleep(10);
82 | }
83 | isFinished = true;
84 | }
85 |
86 | ///
87 | /// 裁剪图片
88 | ///
89 | private BitmapSource GetPartImage(BitmapImage img, int XCoordinate, int YCoordinate, int Width, int Height)
90 | {
91 | return new CroppedBitmap(img, new Int32Rect(XCoordinate, YCoordinate, Width, Height));
92 | }
93 |
94 | ///
95 | /// 获得所有子控件
96 | ///
97 | private List GetChildObjects(System.Windows.DependencyObject obj) where T : System.Windows.FrameworkElement
98 | {
99 | System.Windows.DependencyObject child = null;
100 | List childList = new List();
101 | for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
102 | {
103 | child = VisualTreeHelper.GetChild(obj, i);
104 | if (child is T)
105 | {
106 | childList.Add((T)child);
107 | }
108 | childList.AddRange(GetChildObjects(child));
109 | }
110 | return childList;
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/MyRollControl.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D切图式过渡效果/MyRollControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages._3D切图式过渡效果
17 | {
18 | ///
19 | /// MyRollControl.xaml 的交互逻辑
20 | ///
21 | public partial class MyRollControl : UserControl
22 | {
23 | public MyRollControl()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | ///
29 | /// 滚动数值
30 | ///
31 | public int n_index = 0;
32 |
33 | ///
34 | /// 图片列表
35 | ///
36 | public List ls_images;
37 |
38 | ///
39 | /// 启动
40 | ///
41 | public void Begin()
42 | {
43 | SetRollImageBtnState();
44 | this.ResetStory(DirectionType.right);
45 | this.Cube3D.GetFlipImage();
46 | }
47 |
48 | ///
49 | /// 初始化图片
50 | ///
51 | void ResetStory(DirectionType direction)
52 | {
53 | //向左滚动
54 | if (direction == DirectionType.left)
55 | {
56 | this.Cube3D.FrontImage = this.ls_images[this.n_index % this.ls_images.Count];
57 |
58 | if (this.n_index > 0)
59 | {
60 | this.Cube3D.BackImage = this.ls_images[(this.n_index - 1) % this.ls_images.Count];
61 | }
62 | }
63 | //向右滚动
64 | else
65 | {
66 | this.Cube3D.FrontImage = this.ls_images[this.n_index % this.ls_images.Count];
67 | if (this.n_index < this.ls_images.Count - 1)
68 | {
69 | this.Cube3D.BackImage = this.ls_images[(this.n_index + 1) % this.ls_images.Count];
70 | }
71 | }
72 | }
73 |
74 | private void ImgLeft_MouseDown(object sender, MouseButtonEventArgs e)
75 | {
76 | SetRoll(DirectionType.left);
77 | }
78 |
79 | private void ImgRight_MouseDown(object sender, MouseButtonEventArgs e)
80 | {
81 | SetRoll(DirectionType.right);
82 | }
83 |
84 | ///
85 | /// 左右滚动逻辑
86 | ///
87 | private void SetRoll(DirectionType direction)
88 | {
89 | if (direction == DirectionType.left)
90 | {
91 | if (this.imgLeft.IsEnabled == true)
92 | {
93 | if (!this.Cube3D.isFinished)
94 | {
95 | this.Cube3D.ShowAnimation();
96 | }
97 | else
98 | {
99 | this.ResetStory(direction);
100 | this.Cube3D.GetFlipImage();
101 | this.Cube3D.ShowAnimation();
102 | this.n_index--;
103 | }
104 | }
105 | }
106 | else
107 | {
108 | if (this.imgRight.IsEnabled == true)
109 | {
110 | if (!this.Cube3D.isFinished)
111 | {
112 | this.n_index++;
113 | this.Cube3D.ShowAnimation();
114 | }
115 | else
116 | {
117 | this.ResetStory(direction);
118 | this.Cube3D.GetFlipImage();
119 | this.Cube3D.ShowAnimation();
120 | this.n_index++;
121 | }
122 | }
123 | }
124 | SetRollImageBtnState();
125 | }
126 |
127 | ///
128 | /// 设置左右滚动按钮状态
129 | ///
130 | private void SetRollImageBtnState()
131 | {
132 | if (this.n_index <= 0)
133 | {
134 | this.imgLeft.IsEnabled = false;
135 | }
136 | else if (this.n_index > 0 && this.n_index < this.ls_images.Count - 1)
137 | {
138 | this.imgLeft.IsEnabled = true;
139 | this.imgRight.IsEnabled = true;
140 | }
141 | else if (this.n_index >= this.ls_images.Count - 1)
142 | {
143 | this.imgRight.IsEnabled = false;
144 | }
145 | }
146 | }
147 |
148 | public enum DirectionType
149 | {
150 | left,
151 | right
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D发光立方体效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Media.Media3D;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages._3D发光立方体效果
18 | {
19 | ///
20 | /// Index.xaml 的交互逻辑
21 | ///
22 | public partial class Index : Page
23 | {
24 | public Index()
25 | {
26 | InitializeComponent();
27 | }
28 |
29 | private Point pointBefore;
30 |
31 | private void MyViewport3D_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
32 | {
33 | pointBefore = e.GetPosition(this);
34 | }
35 |
36 | private void MyViewport3D_MouseMove(object sender, MouseEventArgs e)
37 | {
38 | if (e.LeftButton == MouseButtonState.Pressed)
39 | {
40 | Point pointAfter = e.GetPosition(this);
41 | var moveX = pointAfter.X - pointBefore.X;
42 | var moveY = pointAfter.Y - pointBefore.Y;
43 | Vector3D axis = new Vector3D(moveX, moveY, 1);
44 | AxisAngleRotation3D aar = this.FindName("myRotate") as AxisAngleRotation3D;
45 | aar.Axis = axis;
46 | aar.Angle = moveX;
47 | }
48 | }
49 |
50 | private void Page_Unloaded(object sender, RoutedEventArgs e)
51 | {
52 |
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D立方体波浪墙效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D立方体波浪墙效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Media.Media3D;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 | using System.Windows.Threading;
17 |
18 | namespace WPF样式收集.Pages._3D立方体波浪墙效果
19 | {
20 | ///
21 | /// Index.xaml 的交互逻辑
22 | ///
23 | public partial class Index : Page
24 | {
25 | private ParticleSystem _ps;
26 | private DispatcherTimer _frameTimer;
27 | private Point pMouse = new Point(9999, 9999);
28 |
29 | public Index()
30 | {
31 | InitializeComponent();
32 |
33 | _frameTimer = new DispatcherTimer();
34 | _frameTimer.Tick += OnFrame;
35 | _frameTimer.Interval = TimeSpan.FromMilliseconds(100);
36 | _frameTimer.Start();
37 |
38 | _ps = new ParticleSystem(30, 30, Colors.White);
39 | WorldModels.Children.Add(_ps.ParticleModel);
40 | _ps.SpawnParticle(50);
41 | }
42 |
43 | private void OnFrame(object sender, EventArgs e)
44 | {
45 | _ps.Update(pMouse);
46 | }
47 |
48 | private void Grid_MouseMove(object sender, MouseEventArgs e)
49 | {
50 | Point mouseposition = e.GetPosition(myViewport);
51 | PointHitTestParameters pointparams = new PointHitTestParameters(mouseposition);
52 | VisualTreeHelper.HitTest(myViewport, null, HTResult, pointparams);
53 | }
54 |
55 | ///
56 | /// 获取鼠标在场景中的3D坐标
57 | ///
58 | public HitTestResultBehavior HTResult(System.Windows.Media.HitTestResult rawresult)
59 | {
60 | RayHitTestResult rayResult = rawresult as RayHitTestResult;
61 | if (rayResult != null)
62 | {
63 | RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;
64 | if (rayMeshResult != null)
65 | {
66 | GeometryModel3D hitgeo = rayMeshResult.ModelHit as GeometryModel3D;
67 | MeshGeometry3D hitmesh = hitgeo.Geometry as MeshGeometry3D;
68 | Point3D p1 = hitmesh.Positions.ElementAt(rayMeshResult.VertexIndex1);
69 | double weight1 = rayMeshResult.VertexWeight1;
70 | Point3D p2 = hitmesh.Positions.ElementAt(rayMeshResult.VertexIndex2);
71 | double weight2 = rayMeshResult.VertexWeight2;
72 | Point3D p3 = hitmesh.Positions.ElementAt(rayMeshResult.VertexIndex3);
73 | double weight3 = rayMeshResult.VertexWeight3;
74 | Point3D prePoint = new Point3D(p1.X * weight1 + p2.X * weight2 + p3.X * weight3, p1.Y * weight1 + p2.Y * weight2 + p3.Y * weight3, p1.Z * weight1 + p2.Z * weight2 + p3.Z * weight3);
75 | pMouse = new Point(prePoint.X, prePoint.Y);
76 | }
77 | }
78 | return HitTestResultBehavior.Continue;
79 | }
80 |
81 | private void Grid_MouseLeave(object sender, MouseEventArgs e)
82 | {
83 | pMouse = new Point(9999, 9999);
84 | }
85 |
86 | private void Page_Unloaded(object sender, RoutedEventArgs e)
87 | {
88 | //避免页面关闭后资源占用
89 | _frameTimer.Stop();
90 | _frameTimer.Tick -= OnFrame;
91 | _frameTimer = null;
92 | _ps = null;
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D立方体波浪墙效果/Particle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Media.Media3D;
7 |
8 | namespace WPF样式收集.Pages._3D立方体波浪墙效果
9 | {
10 | class Particle
11 | {
12 | public Point3D Position;//位置
13 | public double Width;//长方体底面宽
14 | public double Height;//长方体侧面高
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D立方体波浪墙效果/ParticleSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Media;
8 | using System.Windows.Media.Media3D;
9 |
10 | namespace WPF样式收集.Pages._3D立方体波浪墙效果
11 | {
12 | class ParticleSystem
13 | {
14 | private readonly List _particleList;
15 | private readonly GeometryModel3D _particleModel;
16 | private readonly int CUBOIDHEIGHT = 20;
17 | private readonly int MOUSERADIUS = 1000;
18 | private int XParticleCount;
19 | private int YParticleCount;
20 | public Model3D ParticleModel => _particleModel;
21 |
22 | public ParticleSystem(int amountX, int amountY, Color color)
23 | {
24 | XParticleCount = amountX;
25 | YParticleCount = amountY;
26 |
27 | _particleList = new List();
28 | _particleModel = new GeometryModel3D { Geometry = new MeshGeometry3D() };
29 | var material = new DiffuseMaterial(new SolidColorBrush(color));
30 | _particleModel.Material = material;
31 | }
32 |
33 | public void SpawnParticle(double size)
34 | {
35 | // 初始化粒子位置和大小
36 | for (int ix = 0; ix < XParticleCount; ix++)
37 | {
38 | for (int iy = 0; iy < YParticleCount; iy++)
39 | {
40 | var p = new Particle
41 | {
42 | Position = new Point3D(ix * size, iy * size, 0),
43 | Width = size,
44 | Height = CUBOIDHEIGHT,
45 | };
46 | _particleList.Add(p);
47 | }
48 | }
49 | }
50 |
51 | public void Update(Point mp)
52 | {
53 | foreach (var p in _particleList)
54 | {
55 | //求点到圆心的距离
56 | double c = Math.Pow(Math.Pow(mp.X - p.Position.X, 2) + Math.Pow(mp.Y - p.Position.Y, 2), 0.5);
57 | p.Height = (MOUSERADIUS / (c + CUBOIDHEIGHT)) * CUBOIDHEIGHT;
58 | }
59 | UpdateGeometry();
60 | }
61 |
62 | private void UpdateGeometry()
63 | {
64 | var positions = new Point3DCollection();
65 | var indices = new Int32Collection();
66 |
67 | for (var i = 0; i < _particleList.Count; ++i)
68 | {
69 | var positionIndex = i * 8;
70 | var p = _particleList[i];
71 |
72 | var p1 = new Point3D(p.Position.X, p.Position.Y, p.Position.Z);
73 | var p2 = new Point3D(p.Position.X + p.Width, p.Position.Y, p.Position.Z);
74 | var p3 = new Point3D(p.Position.X + p.Width, p.Position.Y + p.Width, p.Position.Z);
75 | var p4 = new Point3D(p.Position.X, p.Position.Y + p.Width, p.Position.Z);
76 | var p5 = new Point3D(p.Position.X, p.Position.Y, p.Position.Z + p.Height);
77 | var p6 = new Point3D(p.Position.X + p.Width, p.Position.Y, p.Position.Z + p.Height);
78 | var p7 = new Point3D(p.Position.X + p.Width, p.Position.Y + p.Width, p.Position.Z + p.Height);
79 | var p8 = new Point3D(p.Position.X, p.Position.Y + p.Width, p.Position.Z + p.Height);
80 |
81 | positions.Add(p1);
82 | positions.Add(p2);
83 | positions.Add(p3);
84 | positions.Add(p4);
85 | positions.Add(p5);
86 | positions.Add(p6);
87 | positions.Add(p7);
88 | positions.Add(p8);
89 |
90 | indices.Add(positionIndex);
91 | indices.Add(positionIndex + 1);
92 | indices.Add(positionIndex + 3);
93 | indices.Add(positionIndex + 1);
94 | indices.Add(positionIndex + 2);
95 | indices.Add(positionIndex + 3);
96 | indices.Add(positionIndex);
97 | indices.Add(positionIndex + 4);
98 | indices.Add(positionIndex + 3);
99 | indices.Add(positionIndex + 4);
100 | indices.Add(positionIndex + 7);
101 | indices.Add(positionIndex + 3);
102 | indices.Add(positionIndex + 4);
103 | indices.Add(positionIndex + 6);
104 | indices.Add(positionIndex + 7);
105 | indices.Add(positionIndex + 4);
106 | indices.Add(positionIndex + 5);
107 | indices.Add(positionIndex + 6);
108 | indices.Add(positionIndex);
109 | indices.Add(positionIndex + 4);
110 | indices.Add(positionIndex + 1);
111 | indices.Add(positionIndex + 1);
112 | indices.Add(positionIndex + 4);
113 | indices.Add(positionIndex + 5);
114 | indices.Add(positionIndex + 1);
115 | indices.Add(positionIndex + 2);
116 | indices.Add(positionIndex + 6);
117 | indices.Add(positionIndex + 6);
118 | indices.Add(positionIndex + 5);
119 | indices.Add(positionIndex + 1);
120 | indices.Add(positionIndex + 2);
121 | indices.Add(positionIndex + 3);
122 | indices.Add(positionIndex + 7);
123 | indices.Add(positionIndex + 7);
124 | indices.Add(positionIndex + 6);
125 | indices.Add(positionIndex + 2);
126 | }
127 |
128 | ((MeshGeometry3D)_particleModel.Geometry).Positions = positions;
129 | ((MeshGeometry3D)_particleModel.Geometry).TriangleIndices = indices;
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D粒子波浪效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D粒子波浪效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 | using System.Windows.Threading;
16 |
17 | namespace WPF样式收集.Pages._3D粒子波浪效果
18 | {
19 | ///
20 | /// Index.xaml 的交互逻辑
21 | ///
22 | public partial class Index : Page
23 | {
24 | private ParticleSystem _ps;
25 | private DispatcherTimer _frameTimer;
26 | public Index()
27 | {
28 | InitializeComponent();
29 |
30 | _frameTimer = new DispatcherTimer();
31 | _frameTimer.Tick += OnFrame;
32 | _frameTimer.Interval = TimeSpan.FromSeconds(1.0 / 60.0);
33 | _frameTimer.Start();
34 |
35 | _ps = new ParticleSystem(50, 50, Colors.White, 30);
36 |
37 | WorldModels.Children.Add(_ps.ParticleModel);
38 |
39 | _ps.SpawnParticle(30);
40 |
41 | Cursor = Cursors.None;
42 | }
43 |
44 | private void OnFrame(object sender, EventArgs e)
45 | {
46 | _ps.Update();
47 | }
48 |
49 | private void Page_Unloaded(object sender, RoutedEventArgs e)
50 | {
51 | //避免页面关闭后资源占用
52 | _frameTimer.Stop();
53 | _frameTimer.Tick -= OnFrame;
54 | _frameTimer = null;
55 | _ps = null;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D粒子波浪效果/Particle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Media.Media3D;
7 |
8 | namespace WPF样式收集.Pages._3D粒子波浪效果
9 | {
10 | class Particle
11 | {
12 | public Point3D Position;//位置
13 | public double Size;//尺寸
14 | public int XIndex;//X位置标识
15 | public int YIndex;//Y位置标识
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D粒子波浪效果/ParticleSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Media;
8 | using System.Windows.Media.Imaging;
9 | using System.Windows.Media.Media3D;
10 | using System.Windows.Shapes;
11 |
12 | namespace WPF样式收集.Pages._3D粒子波浪效果
13 | {
14 | class ParticleSystem
15 | {
16 | private readonly List _particleList;
17 | private readonly GeometryModel3D _particleModel;
18 | private readonly int SEPARATION = 100;
19 |
20 | public ParticleSystem(int amountX, int amountY, Color color, int Size)
21 | {
22 | XParticleCount = amountX;
23 | YParticleCount = amountY;
24 |
25 | _particleList = new List();
26 |
27 | _particleModel = new GeometryModel3D { Geometry = new MeshGeometry3D() };
28 |
29 | var e = new Ellipse
30 | {
31 | Width = Size,
32 | Height = Size
33 | };
34 | var b = new RadialGradientBrush();
35 | b.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, color.R, color.G, color.B), 0.25));
36 | b.GradientStops.Add(new GradientStop(Color.FromArgb(0x00, color.R, color.G, color.B), 1.0));
37 | e.Fill = b;
38 | e.Measure(new Size(Size, Size));
39 | e.Arrange(new Rect(0, 0, Size, Size));
40 |
41 | Brush brush = null;
42 | var renderTarget = new RenderTargetBitmap(Size, Size, 96, 96, PixelFormats.Pbgra32);
43 | renderTarget.Render(e);
44 | renderTarget.Freeze();
45 | brush = new ImageBrush(renderTarget);
46 |
47 | var material = new DiffuseMaterial(brush);
48 | _particleModel.Material = material;
49 | }
50 |
51 | public int XParticleCount { get; set; }
52 | public int YParticleCount { get; set; }
53 | public Model3D ParticleModel => _particleModel;
54 | private double _count = 0;
55 |
56 | public void Update()
57 | {
58 | // 计算粒子位置及大小
59 | for (int ix = 0; ix < XParticleCount; ix++)
60 | {
61 | for (int iy = 0; iy < YParticleCount; iy++)
62 | {
63 | foreach (var p in _particleList)
64 | {
65 | if (p.XIndex == ix && p.YIndex == iy)
66 | {
67 | p.Position.Z = (Math.Sin((ix + _count) * 0.3) * 100) + (Math.Sin((iy + _count) * 0.5) * 100);
68 | p.Size = (Math.Sin((ix + _count) * 0.3) + 1) * 8 + (Math.Sin((iy + _count) * 0.5) + 1) * 8;
69 | }
70 | }
71 | }
72 | }
73 | _count += 0.1;
74 |
75 | UpdateGeometry();
76 | }
77 |
78 | private void UpdateGeometry()
79 | {
80 | var positions = new Point3DCollection();
81 | var indices = new Int32Collection();
82 | var texcoords = new PointCollection();
83 |
84 | for (var i = 0; i < _particleList.Count; ++i)
85 | {
86 | var positionIndex = i * 4;
87 | var indexIndex = i * 6;
88 | var p = _particleList[i];
89 |
90 | var p1 = new Point3D(p.Position.X, p.Position.Y, p.Position.Z);
91 | var p2 = new Point3D(p.Position.X, p.Position.Y + p.Size, p.Position.Z);
92 | var p3 = new Point3D(p.Position.X + p.Size, p.Position.Y + p.Size, p.Position.Z);
93 | var p4 = new Point3D(p.Position.X + p.Size, p.Position.Y, p.Position.Z);
94 |
95 | positions.Add(p1);
96 | positions.Add(p2);
97 | positions.Add(p3);
98 | positions.Add(p4);
99 |
100 | var t1 = new Point(0.0, 0.0);
101 | var t2 = new Point(0.0, 1.0);
102 | var t3 = new Point(1.0, 1.0);
103 | var t4 = new Point(1.0, 0.0);
104 |
105 | texcoords.Add(t1);
106 | texcoords.Add(t2);
107 | texcoords.Add(t3);
108 | texcoords.Add(t4);
109 |
110 | indices.Add(positionIndex);
111 | indices.Add(positionIndex + 2);
112 | indices.Add(positionIndex + 1);
113 | indices.Add(positionIndex);
114 | indices.Add(positionIndex + 3);
115 | indices.Add(positionIndex + 2);
116 | }
117 |
118 | ((MeshGeometry3D)_particleModel.Geometry).Positions = positions;
119 | ((MeshGeometry3D)_particleModel.Geometry).TriangleIndices = indices;
120 | ((MeshGeometry3D)_particleModel.Geometry).TextureCoordinates = texcoords;
121 | }
122 |
123 | public void SpawnParticle(double size)
124 | {
125 | // 初始化粒子位置和大小
126 | for (int ix = 0; ix < XParticleCount; ix++)
127 | {
128 | for (int iy = 0; iy < YParticleCount; iy++)
129 | {
130 | var p = new Particle
131 | {
132 | Position = new Point3D(ix * SEPARATION - ((XParticleCount * SEPARATION) / 2), iy * SEPARATION - ((YParticleCount * SEPARATION) / 2), 0),
133 | Size = size,
134 | XIndex = ix,
135 | YIndex = iy,
136 | };
137 | _particleList.Add(p);
138 | }
139 | }
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/3D翻转/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages._3D翻转
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void Page_Unloaded(object sender, RoutedEventArgs e)
29 | {
30 |
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/DNA螺旋粒子动画/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/DNA螺旋粒子动画/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.DNA螺旋粒子动画
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | private ParticleSystem ps;
24 |
25 | public Index()
26 | {
27 | InitializeComponent();
28 | }
29 |
30 | private void Page_Loaded(object sender, RoutedEventArgs e)
31 | {
32 | ps = new ParticleSystem(this.cvs_particleContainer);
33 | //注册帧动画
34 | CompositionTarget.Rendering += CompositionTarget_Rendering;
35 | }
36 | ///
37 | /// 帧渲染事件
38 | ///
39 | private void CompositionTarget_Rendering(object sender, EventArgs e)
40 | {
41 | ps.Update();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/DNA螺旋粒子动画/Particle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Shapes;
8 |
9 | namespace WPF样式收集.Pages.DNA螺旋粒子动画
10 | {
11 | class Particle
12 | {
13 | ///
14 | /// 形状
15 | ///
16 | public Ellipse Shape;
17 | ///
18 | /// 坐标
19 | ///
20 | public Point Position;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/DNA螺旋粒子动画/ParticleSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Media;
9 | using System.Windows.Shapes;
10 |
11 | namespace WPF样式收集.Pages.DNA螺旋粒子动画
12 | {
13 | class ParticleSystem
14 | {
15 | ///
16 | /// 粒子步数
17 | ///
18 | private int particleCount = 60;
19 |
20 | ///
21 | /// 间隔
22 | ///
23 | private readonly int SEPARATION = 30;
24 |
25 | ///
26 | /// Y振幅
27 | ///
28 | private int YMax = 50;
29 |
30 | ///
31 | /// 粒子最大尺寸
32 | ///
33 | private int sizeMax = 8;
34 |
35 | ///
36 | /// 粒子列表
37 | ///
38 | private List particleList1, particleList2;
39 |
40 | ///
41 | /// 粒子容器
42 | ///
43 | private Canvas containerParticles;
44 |
45 | ///
46 | /// 计算量
47 | ///
48 | private double count = 0;
49 |
50 | public ParticleSystem(Canvas cv)
51 | {
52 | containerParticles = cv;
53 | particleList1 = new List();
54 | particleList2 = new List();
55 | SpawnParticle();
56 | }
57 |
58 | ///
59 | /// 初始化粒子
60 | ///
61 | private void SpawnParticle()
62 | {
63 | //清空粒子队列
64 | particleList1.Clear();
65 | particleList2.Clear();
66 | containerParticles.Children.Clear();
67 |
68 | // 初始化粒子位置和大小
69 | for (int i = 0; i < particleCount; i++)
70 | {
71 | var p1 = new Particle
72 | {
73 | Shape = new Ellipse
74 | {
75 | Width = (Math.Sin(i * 0.5) + 2) * sizeMax,
76 | Height = (Math.Sin(i * 0.5) + 2) * sizeMax,
77 | Stretch = System.Windows.Media.Stretch.Fill,
78 | Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)),
79 | },
80 | Position = new Point(i * SEPARATION - ((particleCount * SEPARATION) / 2), Math.Sin(i * 0.5) * YMax)
81 | };
82 | particleList1.Add(p1);
83 | Canvas.SetLeft(p1.Shape, p1.Position.X);
84 | Canvas.SetTop(p1.Shape, p1.Position.Y);
85 | containerParticles.Children.Add(p1.Shape);
86 |
87 | var p2 = new Particle
88 | {
89 | Shape = new Ellipse
90 | {
91 | Width = (Math.Cos(i * (-0.5)) + 2) * sizeMax,
92 | Height = (Math.Cos(i * (-0.5)) + 2) * sizeMax,
93 | Stretch = System.Windows.Media.Stretch.Fill,
94 | Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 255)),
95 | },
96 | Position = new Point(i * SEPARATION - ((particleCount * SEPARATION) / 2), -Math.Sin(i * 0.5) * YMax)
97 | };
98 | particleList2.Add(p2);
99 | Canvas.SetLeft(p2.Shape, p2.Position.X);
100 | Canvas.SetTop(p2.Shape, p2.Position.Y);
101 | containerParticles.Children.Add(p2.Shape);
102 | }
103 | }
104 |
105 | ///
106 | /// 更新粒子位置及大小
107 | ///
108 | public void Update()
109 | {
110 | for (int i = 0; i < particleCount; i++)
111 | {
112 | var p1 = particleList1[i];
113 | p1.Position.Y = Math.Sin((i + count) * 0.5) * YMax;
114 | p1.Shape.Width = p1.Shape.Height = (Math.Sin((i + count) * 0.5) + 2) * sizeMax;
115 | Canvas.SetTop(p1.Shape, p1.Position.Y);
116 |
117 | var p2 = particleList2[i];
118 | p2.Position.Y = -Math.Sin((i + count) * 0.5) * YMax;
119 | p2.Shape.Width = p2.Shape.Height = (Math.Cos((i + count) * (-0.5)) + 2) * sizeMax;
120 | Canvas.SetTop(p2.Shape, p2.Position.Y);
121 | }
122 | count += 0.05;
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/EllipseCircleAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Media;
9 | using System.Windows.Media.Animation;
10 | using System.Windows.Shapes;
11 |
12 | namespace WPF样式收集.Pages.Loading
13 | {
14 | internal class EllipseCircleAnimation : Grid
15 | {
16 | private int ellipseCount = 5;
17 | private Color[] ellipseColors = { (Color)ColorConverter.ConvertFromString("#DB2F00"), (Color)ColorConverter.ConvertFromString("#FF6D37"), (Color)ColorConverter.ConvertFromString("#FFA489"),
18 | (Color)ColorConverter.ConvertFromString("#56BEBF"), (Color)ColorConverter.ConvertFromString("#13A3A5")};
19 |
20 | public void InitEllipse(Point beginPoint)
21 | {
22 | for (int i = 0; i < ellipseCount; i++)
23 | {
24 | Ellipse e = new Ellipse()
25 | {
26 | Fill = new SolidColorBrush(ellipseColors[i]),
27 | Width = 10 + i * 5,
28 | Height = 10 + i * 5,
29 | RenderTransform = new TranslateTransform(beginPoint.X, beginPoint.Y),
30 | HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
31 | VerticalAlignment = System.Windows.VerticalAlignment.Center,
32 | };
33 | this.Children.Add(e);
34 | }
35 | }
36 |
37 | public void BeginPathAnimation(PathGeometry ellipsePath, int duration)
38 | {
39 | Storyboard sb = new Storyboard();
40 | //动画完成事件 再次设置此动画
41 | sb.Completed += (S, E) =>
42 | {
43 | BeginPathAnimation(ellipsePath, duration);
44 | };
45 | for (int i = 0; i < this.Children.Count; i++)
46 | {
47 | DoubleAnimationUsingPath dX = new DoubleAnimationUsingPath()
48 | {
49 | PathGeometry = ellipsePath,
50 | Source = PathAnimationSource.X,
51 | Duration = new Duration(TimeSpan.FromSeconds(duration)),
52 | BeginTime = TimeSpan.FromMilliseconds((this.Children.Count - i) * 200),
53 | FillBehavior = FillBehavior.Stop,
54 | };
55 | DependencyProperty[] propertyChainX = new DependencyProperty[]
56 | {
57 | Ellipse.RenderTransformProperty,
58 | TranslateTransform.XProperty
59 | };
60 | Storyboard.SetTarget(dX, (Ellipse)this.Children[i]);
61 | Storyboard.SetTargetProperty(dX, new PropertyPath("(0).(1)", propertyChainX));
62 |
63 | DoubleAnimationUsingPath dY = new DoubleAnimationUsingPath()
64 | {
65 | PathGeometry = ellipsePath,
66 | Source = PathAnimationSource.Y,
67 | Duration = new Duration(TimeSpan.FromSeconds(duration)),
68 | BeginTime = TimeSpan.FromMilliseconds((this.Children.Count - i) * 200),
69 | FillBehavior = FillBehavior.Stop,
70 | };
71 | DependencyProperty[] propertyChainY = new DependencyProperty[]
72 | {
73 | Ellipse.RenderTransformProperty,
74 | TranslateTransform.YProperty
75 | };
76 | Storyboard.SetTarget(dY, (Ellipse)this.Children[i]);
77 | Storyboard.SetTargetProperty(dY, new PropertyPath("(0).(1)", propertyChainY));
78 |
79 | sb.Children.Add(dX);
80 | sb.Children.Add(dY);
81 | }
82 | sb.Begin();
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/EllipsePendulum.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/EllipsePendulum.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.Loading
17 | {
18 | ///
19 | /// EllipsePendulum.xaml 的交互逻辑
20 | ///
21 | public partial class EllipsePendulum : UserControl
22 | {
23 | public static DependencyProperty FillColorProperty = DependencyProperty.Register("FillColor", typeof(SolidColorBrush), typeof(EllipsePendulum), new PropertyMetadata(null));
24 | public SolidColorBrush FillColor
25 | {
26 | get { return (SolidColorBrush)GetValue(FillColorProperty); }
27 | set { SetValue(FillColorProperty, value); }
28 | }
29 |
30 | public static DependencyProperty ShowTextProperty = DependencyProperty.Register("ShowText", typeof(string), typeof(EllipsePendulum), new PropertyMetadata(null));
31 | public string ShowText
32 | {
33 | get { return (string)GetValue(ShowTextProperty); }
34 | set { SetValue(ShowTextProperty, value); }
35 | }
36 |
37 | public EllipsePendulum()
38 | {
39 | InitializeComponent();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.Loading
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingCircle.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingCircle.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.Loading
17 | {
18 | ///
19 | /// LoadingCircle.xaml 的交互逻辑
20 | ///
21 | public partial class LoadingCircle : UserControl
22 | {
23 | public LoadingCircle()
24 | {
25 | InitializeComponent();
26 | InitCircle();
27 | }
28 |
29 | private void InitCircle()
30 | {
31 | //右上角
32 | EllipseCircleAnimation rightUpCircle = new EllipseCircleAnimation();
33 | rightUpCircle.InitEllipse(new Point(0, 0));
34 | rightUpCircle.BeginPathAnimation(CircleGeometry(new Point(0, 0), new Point(141, 141), 100, true, SweepDirection.Clockwise), 2);
35 | //右下角
36 | EllipseCircleAnimation rightDownCircle = new EllipseCircleAnimation();
37 | rightDownCircle.InitEllipse(new Point(0, 0));
38 | rightDownCircle.BeginPathAnimation(CircleGeometry(new Point(0, 0), new Point(141, -141), 100, true, SweepDirection.Clockwise), 2);
39 | //左上角
40 | EllipseCircleAnimation leftUpCircle = new EllipseCircleAnimation();
41 | leftUpCircle.InitEllipse(new Point(0, 0));
42 | leftUpCircle.BeginPathAnimation(CircleGeometry(new Point(0, 0), new Point(-141, 141), 100, true, SweepDirection.Clockwise), 2);
43 | //左下角
44 | EllipseCircleAnimation leftDownCircle = new EllipseCircleAnimation();
45 | leftDownCircle.InitEllipse(new Point(0, 0));
46 | leftDownCircle.BeginPathAnimation(CircleGeometry(new Point(0, 0), new Point(-141, -141), 100, true, SweepDirection.Clockwise), 2);
47 |
48 | this.mainGrid.Children.Add(rightUpCircle);
49 | this.mainGrid.Children.Add(rightDownCircle);
50 | this.mainGrid.Children.Add(leftUpCircle);
51 | this.mainGrid.Children.Add(leftDownCircle);
52 | }
53 |
54 | ///
55 | /// 获取环形路径
56 | ///
57 | private PathGeometry CircleGeometry(Point firstPoint, Point secondPoint, double radius, bool isLargeArc, SweepDirection direction)
58 | {
59 | PathFigure pathFigure = new PathFigure { IsClosed = true };
60 | pathFigure.StartPoint = firstPoint;
61 | pathFigure.Segments.Add(
62 | new ArcSegment
63 | {
64 | Point = secondPoint,
65 | IsLargeArc = isLargeArc,
66 | Size = new Size(radius, radius),
67 | SweepDirection = direction
68 | });
69 | pathFigure.Segments.Add(
70 | new ArcSegment
71 | {
72 | Point = firstPoint,
73 | IsLargeArc = isLargeArc,
74 | Size = new Size(radius, radius),
75 | SweepDirection = direction
76 | });
77 |
78 | PathGeometry pathGeometry = new PathGeometry();
79 | pathGeometry.Figures.Add(pathFigure);
80 | return pathGeometry;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingLeft2Right.xaml:
--------------------------------------------------------------------------------
1 |
8 |
22 |
23 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingLeft2Right.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Animation;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages.Loading
18 | {
19 | ///
20 | /// LoadingLeft2Right.xaml 的交互逻辑
21 | ///
22 | public partial class LoadingLeft2Right : UserControl
23 | {
24 | public LoadingLeft2Right()
25 | {
26 | InitializeComponent();
27 | }
28 |
29 | private Storyboard LoadingBarBoard = new Storyboard();
30 | DoubleAnimation LoadingAnimation = new DoubleAnimation();
31 | private int DurationTime = 3;
32 |
33 | private void UserControl_Loaded(object sender, RoutedEventArgs e)
34 | {
35 | Init();
36 | }
37 |
38 | private void Init()
39 | {
40 | LoadingAnimation.From = -this.loadingBar.ActualWidth;
41 | LoadingAnimation.To = this.mainCanvas.ActualWidth / 2;
42 | LoadingAnimation.RepeatBehavior = RepeatBehavior.Forever;
43 | LoadingAnimation.Duration = TimeSpan.FromSeconds(DurationTime);
44 | LoadingAnimation.FillBehavior = FillBehavior.Stop;
45 | Storyboard.SetTargetName(LoadingAnimation, "loadingBar");
46 | Storyboard.SetTargetProperty(LoadingAnimation, new PropertyPath(Canvas.LeftProperty));
47 | LoadingBarBoard.Children.Add(LoadingAnimation);
48 | LoadingBarBoard.Begin(this);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingPendulum.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingPendulum.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Animation;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages.Loading
18 | {
19 | ///
20 | /// LoadingPendulum.xaml 的交互逻辑
21 | ///
22 | public partial class LoadingPendulum : UserControl
23 | {
24 |
25 | private string showText = "loading";
26 | private Color[] ellipseColors = { (Color)ColorConverter.ConvertFromString("#DB2F00"), (Color)ColorConverter.ConvertFromString("#FF6D37"), (Color)ColorConverter.ConvertFromString("#FFA489"),
27 | (Color)ColorConverter.ConvertFromString("#FFFFFF"), (Color)ColorConverter.ConvertFromString("#99D3D4"), (Color)ColorConverter.ConvertFromString("#56BEBF"), (Color)ColorConverter.ConvertFromString("#13A3A5")};
28 |
29 | public LoadingPendulum()
30 | {
31 | InitializeComponent();
32 | InitEllipse(new Point(0, 0));
33 | BeginKeyFrameAnimation();
34 | }
35 |
36 | public void InitEllipse(Point beginPoint)
37 | {
38 | for (int i = 0; i < showText.Length; i++)
39 | {
40 | EllipsePendulum e = new EllipsePendulum()
41 | {
42 | FillColor = new SolidColorBrush(ellipseColors[i]),
43 | ShowText = showText.Substring(i, 1),
44 | RenderTransform = new TranslateTransform(beginPoint.X, beginPoint.Y),
45 | HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
46 | VerticalAlignment = System.Windows.VerticalAlignment.Center,
47 | Margin = new Thickness(100 + i * 80, 0, 0, 0),
48 | };
49 | this.mainGrid.Children.Add(e);
50 | }
51 | }
52 |
53 | public void BeginKeyFrameAnimation()
54 | {
55 | Storyboard sb = new Storyboard();
56 | //动画完成事件 再次设置此动画
57 | sb.Completed += (S, E) =>
58 | {
59 | BeginKeyFrameAnimation();
60 | };
61 | DependencyProperty[] propertyChain = new DependencyProperty[]
62 | {
63 | EllipsePendulum.RenderTransformProperty,
64 | TranslateTransform.XProperty
65 | };
66 | for (int i = 0; i < this.mainGrid.Children.Count; i++)
67 | {
68 | DoubleKeyFrameCollection frameCollection = new DoubleKeyFrameCollection();
69 | DoubleAnimationUsingKeyFrames dakf = new DoubleAnimationUsingKeyFrames()
70 | {
71 | Duration = new Duration(TimeSpan.FromSeconds(1)),
72 | BeginTime = TimeSpan.FromMilliseconds(i * 500),
73 | FillBehavior = FillBehavior.HoldEnd,
74 | KeyFrames = frameCollection,
75 | AutoReverse = true,
76 | };
77 | if (i == 0)
78 | {
79 | //首球要向左摆动一下模仿开始撞击动作,它不需要自动反向
80 | dakf.AutoReverse = false;
81 | DiscreteDoubleKeyFrame dd = new DiscreteDoubleKeyFrame()
82 | {
83 | Value = -50,
84 | KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
85 | };
86 | frameCollection.Add(dd);
87 | }
88 | //向右摆动
89 | SplineDoubleKeyFrame sd = new SplineDoubleKeyFrame()
90 | {
91 | Value = 50,
92 | KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)),
93 | KeySpline = new KeySpline(new Point(0, 0), new Point(0, 1)),
94 | };
95 | frameCollection.Add(sd);
96 | Storyboard.SetTarget(dakf, this.mainGrid.Children[i]);
97 | Storyboard.SetTargetProperty(dakf, new PropertyPath("(0).(1)", propertyChain));
98 | sb.Children.Add(dakf);
99 | }
100 | //首球返回原位
101 | DoubleAnimation da = new DoubleAnimation()
102 | {
103 | Duration = new Duration(TimeSpan.FromSeconds(1)),
104 | BeginTime = TimeSpan.FromSeconds(1),
105 | FillBehavior = FillBehavior.HoldEnd,
106 | From = 50,
107 | To = 0,
108 | };
109 | Storyboard.SetTarget(da, this.mainGrid.Children[0]);
110 | Storyboard.SetTargetProperty(da, new PropertyPath("(0).(1)", propertyChain));
111 | sb.Children.Add(da);
112 | sb.Begin();
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingWave.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Loading/LoadingWave.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 | using System.Windows.Threading;
16 |
17 | namespace WPF样式收集.Pages.Loading
18 | {
19 | ///
20 | /// LoadingWave.xaml 的交互逻辑
21 | ///
22 | public partial class LoadingWave : UserControl
23 | {
24 | public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(LoadingWave), new PropertyMetadata(null));
25 | public int Value
26 | {
27 | get { return (int)GetValue(ValueProperty); }
28 | set { SetValue(ValueProperty, value); }
29 | }
30 |
31 | private DispatcherTimer frameTimer;
32 | private StreamGeometry myPathGeometry;
33 |
34 | public LoadingWave()
35 | {
36 | InitializeComponent();
37 |
38 | CompositionTarget.Rendering += UpdateRectangle;
39 |
40 | frameTimer = new DispatcherTimer();
41 | frameTimer.Tick += OnFrame;
42 | frameTimer.Interval = TimeSpan.FromSeconds(3.0 / 60.0);
43 | frameTimer.Start();
44 | }
45 |
46 | private void OnFrame(object sender, EventArgs e)
47 | {
48 | this.GeometryCanvas.Children.Clear();
49 | if (Value > 100)
50 | {
51 | if (frameTimer != null)
52 | frameTimer.Stop();
53 | }
54 | Value++;
55 | myPathGeometry = GetSinGeometry(this.Width, -5, 1 / 30.0, -this.Width + this.Width * Value / 100, this.Height - this.Height * Value / 100);
56 | GeometryGroup group = new GeometryGroup();
57 | group.Children.Add(myPathGeometry);
58 |
59 | Path myPath = new Path();
60 | myPath.Fill = Brushes.Transparent;
61 | myPath.Data = group;
62 |
63 | this.GeometryCanvas.Children.Add(myPath);
64 | }
65 |
66 | private void UpdateRectangle(object sender, EventArgs e)
67 | {
68 | this.GeometryText.Clip = myPathGeometry;
69 | }
70 | ///
71 | /// 得到正弦曲线
72 | ///
73 | /// 水纹宽度
74 | /// 水纹振幅
75 | /// 水纹周期
76 | /// 位移
77 | /// 当前波浪高度
78 | ///
79 | public StreamGeometry GetSinGeometry(double waveWidth, double waveA, double waveW, double offsetX, double currentK)
80 | {
81 | StreamGeometry g = new StreamGeometry();
82 | using (StreamGeometryContext ctx = g.Open())
83 | {
84 | ctx.BeginFigure(new Point(0, 0), true, true);
85 | for (int x = 0; x < waveWidth; x += 1)
86 | {
87 | double y = waveA * Math.Sin(x * waveW + offsetX) + currentK;
88 | ctx.LineTo(new Point(x, y), true, true);
89 | }
90 | ctx.LineTo(new Point(waveWidth, 0), true, true);
91 | }
92 | return g;
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Welcome.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/Welcome.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages
17 | {
18 | ///
19 | /// Welcome.xaml 的交互逻辑
20 | ///
21 | public partial class Welcome : Page
22 | {
23 | public Welcome()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图像倾斜视差效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图像倾斜视差效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.图像倾斜视差效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图像倾斜视差效果/MyImageControl2D.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图像倾斜视差效果/MyImageControl2D.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.图像倾斜视差效果
17 | {
18 | ///
19 | /// MyImageControl2D.xaml 的交互逻辑
20 | ///
21 | public partial class MyImageControl2D : UserControl
22 | {
23 | public static readonly DependencyProperty ShowImageProperty = DependencyProperty.Register("ShowImage", typeof(ImageSource), typeof(MyImageControl2D), new PropertyMetadata(null));
24 | public ImageSource ShowImage
25 | {
26 | get { return (ImageSource)GetValue(ShowImageProperty); }
27 | set { SetValue(ShowImageProperty, value); }
28 | }
29 |
30 | public int extraImgCount = 4;//图片个数
31 | public double ImgOpacity = 0.5;//除底图外图片透明度
32 | public int ImgTranslate = 15;//图片位移量
33 |
34 | public MyImageControl2D()
35 | {
36 | InitializeComponent();
37 | this.Loaded += MyImageControl2D_Loaded;
38 | }
39 |
40 | private void MyImageControl2D_Loaded(object sender, RoutedEventArgs e)
41 | {
42 | InitShowImage();
43 | this.mainGrid.MouseLeave += MainGrid_MouseLeave;
44 | this.mainGrid.MouseMove += MainGrid_MouseMove;
45 | }
46 |
47 | ///
48 | /// 初始化加载Image控件
49 | ///
50 | private void InitShowImage()
51 | {
52 | for (int i = 0; i < extraImgCount; i++)
53 | {
54 | Image img = new Image
55 | {
56 | Source = ShowImage,
57 | Stretch = Stretch.Fill,
58 | Opacity = i > 0 ? ImgOpacity : 1,
59 | };
60 | var trans = new TranslateTransform();
61 | img.RenderTransform = trans;
62 | this.mainGrid.Children.Add(img);
63 | }
64 | }
65 |
66 | private void MainGrid_MouseMove(object sender, MouseEventArgs e)
67 | {
68 | var moveX = e.GetPosition(this.mainGrid).X / this.mainGrid.ActualWidth - 0.5;
69 | var moveY = e.GetPosition(this.mainGrid).Y / this.mainGrid.ActualHeight - 0.5;
70 |
71 | List imgs = GetChildObjects(this.mainGrid);
72 | for (int i = 1; i < imgs.Count; i++)
73 | {
74 | TranslateTransform trans = imgs[i].RenderTransform as TranslateTransform;
75 | trans.X = moveX * ImgTranslate * i;
76 | trans.Y = moveY * ImgTranslate * i;
77 | }
78 | }
79 |
80 | private void MainGrid_MouseLeave(object sender, MouseEventArgs e)
81 | {
82 | List imgs = GetChildObjects(this.mainGrid);
83 | for (int i = 1; i < imgs.Count; i++)
84 | {
85 | TranslateTransform trans = imgs[i].RenderTransform as TranslateTransform;
86 | trans.X = 0;
87 | trans.Y = 0;
88 | }
89 | }
90 | ///
91 | /// 获得所有子控件
92 | ///
93 | private List GetChildObjects(System.Windows.DependencyObject obj) where T : System.Windows.FrameworkElement
94 | {
95 | System.Windows.DependencyObject child = null;
96 | List childList = new List();
97 | for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
98 | {
99 | child = VisualTreeHelper.GetChild(obj, i);
100 | if (child is T)
101 | {
102 | childList.Add((T)child);
103 | }
104 | childList.AddRange(GetChildObjects(child));
105 | }
106 | return childList;
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片变换动画/BlockAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Media;
6 | using System.Windows;
7 | using System.Windows.Threading;
8 |
9 | namespace WPF样式收集.Pages.图片变换动画
10 | {
11 | class BlockAnimation
12 | {
13 | DispatcherTimer _timer = null;
14 | PathGeometry pathGeometry = null;
15 | double _rectangleSize = 80;
16 | double _numberofrectangles = 0;
17 | RandomNumberFromAGivenSetOfNumbers rdm = null;
18 | int _numberOfalreadyDrawnRectangles = 0;
19 | double _height = 0;
20 | double _width = 0;
21 | FrameworkElement _animatedElement = null;
22 | public event Action AnimationCompleted;
23 | public void MakeBlockAnimation(FrameworkElement animatedElement, double width, double height, TimeSpan timeSpan)
24 | {
25 |
26 | _animatedElement = animatedElement;
27 | _height = width;
28 | _width = height;
29 | if (_height > _width)
30 | {
31 | _numberofrectangles = Math.Ceiling(_height / _rectangleSize);
32 | }
33 | else
34 | {
35 | _numberofrectangles = Math.Ceiling(_width / _rectangleSize);
36 |
37 | }
38 |
39 | rdm = new RandomNumberFromAGivenSetOfNumbers(0, Convert.ToInt32(_numberofrectangles * _numberofrectangles - 1));
40 |
41 | double steps = _numberofrectangles * _numberofrectangles;
42 | double tickTime = timeSpan.TotalSeconds / steps;
43 |
44 | pathGeometry = new PathGeometry();
45 | _animatedElement.Clip = pathGeometry;
46 | _timer = new DispatcherTimer(DispatcherPriority.Input);
47 | _timer.Interval = TimeSpan.FromSeconds(tickTime);
48 | _timer.Tick += new EventHandler(_timer_Tick);
49 | _timer.IsEnabled = true;
50 |
51 | }
52 |
53 | void _timer_Tick(object sender, EventArgs e)
54 | {
55 |
56 | int random = rdm.Next();
57 | int i = random / (int)_numberofrectangles;
58 | int j = random % (int)_numberofrectangles;
59 | RectangleGeometry myRectGeometry2 = new RectangleGeometry();
60 | myRectGeometry2.Rect = new Rect(j * _rectangleSize, i * _rectangleSize, _rectangleSize, _rectangleSize);
61 | pathGeometry = Geometry.Combine(pathGeometry, myRectGeometry2, GeometryCombineMode.Union, null);
62 | _animatedElement.Clip = pathGeometry;
63 |
64 | if (_numberOfalreadyDrawnRectangles == _numberofrectangles * _numberofrectangles)
65 | {
66 | _timer.IsEnabled = false;
67 | if (AnimationCompleted != null)
68 | {
69 | AnimationCompleted();
70 | }
71 | }
72 |
73 | _numberOfalreadyDrawnRectangles++;
74 |
75 | }
76 |
77 |
78 | }
79 |
80 | class RandomNumberFromAGivenSetOfNumbers
81 | {
82 | List _setOfNumbers = new List();
83 | Random _random = new Random();
84 | public RandomNumberFromAGivenSetOfNumbers(int min, int max)
85 | {
86 | for (int i = min; i <= max; i++)
87 | {
88 | _setOfNumbers.Add(i);
89 | }
90 | }
91 |
92 | public int Next()
93 | {
94 | if (_setOfNumbers.Count > 0)
95 | {
96 | int nextNumberIndex = _random.Next(_setOfNumbers.Count);
97 | int val = _setOfNumbers[nextNumberIndex];
98 | _setOfNumbers.RemoveAt(nextNumberIndex);
99 | return val;
100 | }
101 | return -1;
102 |
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片变换动画/CircleAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 | using System.Windows.Media;
7 | using System.Windows.Media.Animation;
8 |
9 | namespace WPF样式收集.Pages.图片变换动画
10 | {
11 | class CircleAnimation
12 | {
13 | public event Action AnimationCompleted;
14 | public void MakeCircleAnimation(FrameworkElement animatedElement, double width, double height, TimeSpan timeSpan)
15 | {
16 | EllipseGeometry ellipseGeometry = new EllipseGeometry();
17 | ellipseGeometry.RadiusX = 0;
18 | ellipseGeometry.RadiusY = 0;
19 | double centrex = width / 2;
20 | double centrey = height / 2;
21 | ellipseGeometry.Center = new Point(centrex, centrey);
22 | animatedElement.Clip = ellipseGeometry; //The most important line
23 | double halfWidth = width / 2;
24 | double halfheight = height / 2;
25 | DoubleAnimation a = new DoubleAnimation();
26 | a.Completed += new EventHandler(a_Completed);
27 | a.From = 0;
28 | a.To = Math.Sqrt(halfWidth * halfWidth + halfheight * halfheight);
29 | a.Duration = new Duration(timeSpan);
30 | ellipseGeometry.BeginAnimation(EllipseGeometry.RadiusXProperty, a);
31 | ellipseGeometry.BeginAnimation(EllipseGeometry.RadiusYProperty, a);
32 |
33 | }
34 |
35 | void a_Completed(object sender, EventArgs e)
36 | {
37 | if (AnimationCompleted != null)
38 | {
39 | AnimationCompleted();
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片变换动画/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
20 |
21 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片变换动画/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.图片变换动画
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void Page_Unloaded(object sender, RoutedEventArgs e)
29 | {
30 |
31 | }
32 |
33 | private void Page_Loaded(object sender, RoutedEventArgs e)
34 | {
35 | image.Source = loadBitmap(WPF样式收集.Properties.Resources.images1);
36 | }
37 | public static BitmapSource loadBitmap(System.Drawing.Bitmap source)
38 | {
39 | return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
40 | System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
41 | }
42 |
43 | private void Button_Click(object sender, RoutedEventArgs e)
44 | {
45 | btnAnimate.IsEnabled = false;
46 | if (comboBox1.Text == "Circle")
47 | {
48 | CircleAnimation circleAnimationHelper = new CircleAnimation();
49 | circleAnimationHelper.AnimationCompleted += new Action(circleAnimationHelper_AnimationCompleted);
50 | circleAnimationHelper.MakeCircleAnimation((FrameworkElement)image, image.Width, image.Height, new TimeSpan(0, 0, 5));
51 | }
52 | else if (comboBox1.Text == "Radial")
53 | {
54 | RadialAnimation radialAnimationHelper = new RadialAnimation();
55 | radialAnimationHelper.AnimationCompleted += new Action(circleAnimationHelper_AnimationCompleted);
56 | radialAnimationHelper.MakeRadiaAnimation((FrameworkElement)image, image.Width, image.Height, new TimeSpan(0, 0, 5));
57 | }
58 | else if (comboBox1.Text == "Block")
59 | {
60 | BlockAnimation blockAnimationHelper = new BlockAnimation();
61 | blockAnimationHelper.AnimationCompleted += new Action(circleAnimationHelper_AnimationCompleted);
62 | blockAnimationHelper.MakeBlockAnimation((FrameworkElement)image, image.Width, image.Height, new TimeSpan(0, 0, 5));
63 | }
64 | else if (comboBox1.Text == "Interlace")
65 | {
66 |
67 | InterlacedAnimation interlacedAnimation = new InterlacedAnimation();
68 | interlacedAnimation.AnimationCompleted += new Action(circleAnimationHelper_AnimationCompleted);
69 | interlacedAnimation.MakeInterlacedAnimation((FrameworkElement)image, image.Width, image.Height, new TimeSpan(0, 0, 5));
70 | }
71 |
72 | else if (comboBox1.Text == "WaterFall")
73 | {
74 |
75 | WaterFallAnimation WaterFall = new WaterFallAnimation();
76 | WaterFall.AnimationCompleted += new Action(circleAnimationHelper_AnimationCompleted);
77 | WaterFall.MakeWaterFallAnimation((FrameworkElement)image, image.Width, image.Height, new TimeSpan(0, 0, 5));
78 | }
79 |
80 | }
81 |
82 | void circleAnimationHelper_AnimationCompleted()
83 | {
84 | btnAnimate.IsEnabled = true;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片变换动画/InterlacedAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Threading;
6 | using System.Windows.Media;
7 | using System.Windows;
8 |
9 | namespace WPF样式收集.Pages.图片变换动画
10 | {
11 | class InterlacedAnimation
12 | {
13 | DispatcherTimer _timer = null;
14 | PathGeometry pathGeometry = null;
15 | double _rectangleSize = 3;
16 | double _startingCoordinate = 0;
17 | double _endcoordinate = 0;
18 | FrameworkElement _animatedElement = null;
19 | double _width = 0;
20 | double _height = 0;
21 | double _offset = 0.5;
22 | bool IsTimerShouldBeStoppedForUp = false;
23 | bool IsTimerShouldBeStoppedForDown = false;
24 | public event Action AnimationCompleted;
25 | public void MakeInterlacedAnimation(FrameworkElement animatedElement, double width, double height, TimeSpan timeSpan)
26 | {
27 | double steps = (height / (_rectangleSize + _offset));
28 | double tickTime = timeSpan.TotalSeconds / steps;
29 | _animatedElement = animatedElement;
30 | _width = width;
31 | _height = height;
32 | _endcoordinate = height;
33 | pathGeometry = new PathGeometry();
34 | animatedElement.Clip = pathGeometry;
35 | _timer = new DispatcherTimer();
36 | _timer.Interval = TimeSpan.FromSeconds(tickTime);
37 | _timer.Tick += new EventHandler(_timer_Tick);
38 | _timer.IsEnabled = true;
39 | }
40 |
41 |
42 | void _timer_Tick(object sender, EventArgs e)
43 | {
44 |
45 | if (IsTimerShouldBeStoppedForUp == true && IsTimerShouldBeStoppedForDown == true)
46 | {
47 | _timer.IsEnabled = false;
48 | if (AnimationCompleted != null)
49 | {
50 | AnimationCompleted();
51 | }
52 | }
53 |
54 | if (_startingCoordinate == _endcoordinate)
55 | {
56 | _offset = 0;
57 | }
58 | if (_startingCoordinate >= (_height / 2 - 5))
59 | _offset = 0;
60 | if (_endcoordinate <= (_height / 2 - 5))
61 | _offset = 0;
62 |
63 | if (_startingCoordinate < _height)
64 | {
65 | RectangleGeometry myRectGeometry2 = new RectangleGeometry();
66 | myRectGeometry2.Rect = new Rect(0, _startingCoordinate, _width, _rectangleSize);
67 | pathGeometry = Geometry.Combine(pathGeometry, myRectGeometry2, GeometryCombineMode.Union, null);
68 | }
69 | else
70 | {
71 | IsTimerShouldBeStoppedForUp = true;
72 | }
73 |
74 | if (_endcoordinate > 0)
75 | {
76 | RectangleGeometry myRectGeometry3 = new RectangleGeometry();
77 | myRectGeometry3.Rect = new Rect(0, _endcoordinate, _width, _rectangleSize);
78 | pathGeometry = Geometry.Combine(pathGeometry, myRectGeometry3, GeometryCombineMode.Union, null);
79 | }
80 | else
81 | {
82 | IsTimerShouldBeStoppedForDown = true;
83 | }
84 |
85 | _startingCoordinate = _startingCoordinate + _rectangleSize + _offset;
86 | _endcoordinate = _endcoordinate - _rectangleSize - _offset;
87 | _animatedElement.Clip = pathGeometry;
88 |
89 | }
90 |
91 |
92 |
93 |
94 |
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片变换动画/WaterFallAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Threading;
6 | using System.Windows.Media;
7 | using System.Windows;
8 |
9 | namespace WPF样式收集.Pages.图片变换动画
10 | {
11 | class WaterFallAnimation
12 | {
13 | DispatcherTimer _timer = null;
14 | PathGeometry pathGeometry = null;
15 | double _rectangleSize = 10 + 50;
16 | double _offset = 5;
17 | int _waterFallHeight = 50;
18 | double _width = 0;
19 | double _height = 0;
20 | Random random = new Random();
21 | FrameworkElement _animatedElement = null;
22 | RectangleGeometry myRectGeometry2 = null;
23 | PathGeometry pathGeometry2 = null;
24 | RectangleGeometry myRectGeometry5 = null;
25 | public event Action AnimationCompleted;
26 |
27 | public void MakeWaterFallAnimation(FrameworkElement animatedElement, double width, double height, TimeSpan timeSpan)
28 | {
29 | _animatedElement = animatedElement;
30 | _height = height;
31 | _width = width;
32 | myRectGeometry2 = new RectangleGeometry();
33 | pathGeometry2 = new PathGeometry();
34 | myRectGeometry5 = new RectangleGeometry();
35 | double steps = (_height / _offset);
36 | double tickTime = timeSpan.TotalSeconds / steps;
37 | pathGeometry = new PathGeometry();
38 | animatedElement.Clip = pathGeometry;
39 | _timer = new DispatcherTimer(DispatcherPriority.Input);
40 | _timer.Interval = TimeSpan.FromSeconds(tickTime);
41 | _timer.Tick += new EventHandler(_timer_Tick);
42 | _timer.IsEnabled = true;
43 | }
44 |
45 | void _timer_Tick(object sender, EventArgs e)
46 | {
47 | myRectGeometry2.Rect = new Rect(0, 0, _width, _rectangleSize);
48 | pathGeometry2 = Geometry.Combine(pathGeometry2, myRectGeometry2, GeometryCombineMode.Union, null);
49 |
50 | for (int i = 1; i <= _width; i = i + 2)
51 | {
52 | myRectGeometry5.Rect = new Rect(new Point(i, _rectangleSize), new Point(i + 2, _rectangleSize - random.Next(0, _waterFallHeight)));
53 | pathGeometry2 = Geometry.Combine(pathGeometry2, myRectGeometry5, GeometryCombineMode.Exclude, null);
54 | }
55 | _animatedElement.Clip = pathGeometry2;
56 | if (_rectangleSize == _height + _waterFallHeight)
57 | {
58 | _timer.IsEnabled = false;
59 | if (AnimationCompleted != null)
60 | {
61 | AnimationCompleted();
62 | }
63 | }
64 | _rectangleSize += _offset;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片环形旋转轮动效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片环形旋转轮动效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.图片环形旋转轮动效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 |
27 | Global.MainWindow.SetBugs("鼠标有些粘连(当滚动结束于非图片区域时,鼠标事件未处理)");
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片环形旋转轮动效果/MyImageBox.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片环形旋转轮动效果/MyImageBox.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.图片环形旋转轮动效果
17 | {
18 | ///
19 | /// MyImageBox.xaml 的交互逻辑
20 | ///
21 | public partial class MyImageBox : UserControl
22 | {
23 | public static readonly DependencyProperty DisplayImageProperty = DependencyProperty.Register("DisplayImage", typeof(ImageSource), typeof(MyImageBox), new PropertyMetadata(null));
24 | public ImageSource DisplayImage
25 | {
26 | get { return (ImageSource)GetValue(DisplayImageProperty); }
27 | set { SetValue(DisplayImageProperty, value); }
28 | }
29 |
30 | public static readonly DependencyProperty ImageTitleProperty = DependencyProperty.Register("ImageTitle", typeof(String), typeof(MyImageBox), new PropertyMetadata(null));
31 | public String ImageTitle
32 | {
33 | get { return (String)GetValue(ImageTitleProperty); }
34 | set { SetValue(ImageTitleProperty, value); }
35 | }
36 | public double Rotate { set; get; }
37 |
38 | public MyImageBox()
39 | {
40 | InitializeComponent();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片翻转切换特效/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片翻转切换特效/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.图片翻转切换特效
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 |
27 | Global.MainWindow.SetBugs("鼠标快速移动时,识别灵敏度不够,缺少更多的验证条件");
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/图片翻转切换特效/MyImageButton.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/圆形警示效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/圆形警示效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.圆形警示效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 |
27 | RingControl redRing = new RingControl
28 | {
29 | MinSize = 25,
30 | MaxSize = 100,
31 | EllipseNum = 4,
32 | EllipseInterval = 800,
33 | AnimationDuration = 5,
34 | EllipseStroke = new SolidColorBrush(Colors.Red),
35 | EllipseStrokeThickness = 25,
36 | Margin = new Thickness(-150, -300, 0, 0),
37 | };
38 | this.mainGrid.Children.Add(redRing);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/圆形警示效果/RingControl.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/圆形警示效果/RingControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Animation;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace WPF样式收集.Pages.圆形警示效果
18 | {
19 | ///
20 | /// RingControl.xaml 的交互逻辑
21 | ///
22 | public partial class RingControl : UserControl
23 | {
24 | ///
25 | /// 圆的颜色
26 | ///
27 | public Brush EllipseStroke { get; set; }
28 | ///
29 | /// 圆环的宽度
30 | ///
31 | public double EllipseStrokeThickness { get; set; }
32 | ///
33 | /// 圆的最小尺寸
34 | ///
35 | public double MinSize { get; set; }
36 | ///
37 | /// 圆的最大尺寸
38 | ///
39 | public double MaxSize { get; set; }
40 | ///
41 | /// 总圆环数量
42 | ///
43 | public int EllipseNum { get; set; }
44 | ///
45 | /// 不同圆之间的时间间隔
46 | ///
47 | public double EllipseInterval { get; set; }
48 | ///
49 | /// 动画启动等待时间
50 | ///
51 | private double StoryBeginTime { get; set; }
52 | ///
53 | /// 动画持续时间
54 | ///
55 | public double AnimationDuration { get; set; }
56 |
57 | public RingControl()
58 | {
59 | InitializeComponent();
60 | }
61 |
62 | private void MyUserControl_Loaded(object sender, RoutedEventArgs e)
63 | {
64 | Ellipse centerE = new Ellipse()
65 | {
66 | HorizontalAlignment = HorizontalAlignment.Center,
67 | VerticalAlignment = VerticalAlignment.Center,
68 | Width = MinSize,
69 | Height = MinSize,
70 | Stroke = EllipseStroke,
71 | StrokeThickness = EllipseStrokeThickness,
72 | };
73 | this.mainGrid.Children.Add(centerE);
74 | InitAnimation();
75 | }
76 |
77 | private void InitAnimation()
78 | {
79 | for (int i = 1; i <= EllipseNum; i++)
80 | {
81 | Storyboard story = new Storyboard()
82 | {
83 | //是否循环
84 | RepeatBehavior = RepeatBehavior.Forever,
85 | //动画刷新速度
86 | SpeedRatio = 2
87 | };
88 | //透明度调整动作
89 | DoubleAnimation myOpacityAnimation = new DoubleAnimation
90 | {
91 | From = 1,
92 | To = 0,
93 | Duration = new Duration(TimeSpan.FromSeconds(AnimationDuration))
94 | };
95 | story.Children.Add(myOpacityAnimation);
96 | //宽度调整动作
97 | DoubleAnimation myWidthSizeChangeAnimation = new DoubleAnimation
98 | {
99 | From = MinSize,
100 | To = MaxSize,
101 | Duration = new Duration(TimeSpan.FromSeconds(AnimationDuration))
102 | };
103 | story.Children.Add(myWidthSizeChangeAnimation);
104 | //高度调整动作
105 | DoubleAnimation myHeightSizeChangeAnimation = new DoubleAnimation
106 | {
107 | From = MinSize,
108 | To = MaxSize,
109 | Duration = new Duration(TimeSpan.FromSeconds(AnimationDuration))
110 | };
111 | story.Children.Add(myHeightSizeChangeAnimation);
112 | //生成形状
113 | Ellipse tempE = new Ellipse()
114 | {
115 | HorizontalAlignment = HorizontalAlignment.Center,
116 | VerticalAlignment = VerticalAlignment.Center,
117 | Width = MinSize,
118 | Height = MinSize,
119 | Stroke = EllipseStroke,
120 | StrokeThickness = EllipseStrokeThickness,
121 | };
122 | //动画赋值
123 | Storyboard.SetTarget(myOpacityAnimation, tempE);
124 | Storyboard.SetTargetProperty(myOpacityAnimation, new PropertyPath(Ellipse.OpacityProperty));
125 | Storyboard.SetTarget(myWidthSizeChangeAnimation, tempE);
126 | Storyboard.SetTarget(myHeightSizeChangeAnimation, tempE);
127 | Storyboard.SetTargetProperty(myWidthSizeChangeAnimation, new PropertyPath(Ellipse.WidthProperty));
128 | Storyboard.SetTargetProperty(myHeightSizeChangeAnimation, new PropertyPath(Ellipse.HeightProperty));
129 |
130 | mainGrid.Children.Add(tempE);
131 | //时间间隔
132 | StoryBeginTime += EllipseInterval;
133 | story.BeginTime = TimeSpan.FromMilliseconds(StoryBeginTime);
134 | story.Begin();
135 | }
136 | }
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani1.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani1.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.字体动画效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Ani1 : Page
22 | {
23 | public Ani1()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void Page_Unloaded(object sender, RoutedEventArgs e)
29 | {
30 |
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani2.xaml:
--------------------------------------------------------------------------------
1 |
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 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani2.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.字体动画效果
17 | {
18 | ///
19 | /// Ani2.xaml 的交互逻辑
20 | ///
21 | public partial class Ani2 : Page
22 | {
23 | public Ani2()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani3.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
28 |
29 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani3.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.字体动画效果
17 | {
18 | ///
19 | /// Ani3.xaml 的交互逻辑
20 | ///
21 | public partial class Ani3 : Page
22 | {
23 | public Ani3()
24 | {
25 | InitializeComponent();
26 | CompositionTarget.Rendering += UpdateEllipse;
27 | }
28 |
29 |
30 | private void UpdateEllipse(object sender, EventArgs e)
31 | {
32 | this.GeometryText.Clip = this.MyEllipseGeometry;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Ani4.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.字体动画效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Ani4 : Page
22 | {
23 | public Ani4()
24 | {
25 | InitializeComponent();
26 | CompositionTarget.Rendering += UpdateGeometry;
27 | }
28 |
29 | private void UpdateGeometry(object sender, EventArgs e)
30 | {
31 | this.myBgImage.Clip = this.myRectangleGeometry3;
32 | this.myGeometryImage1.Clip = this.myRectangleGeometry1;
33 | this.myGeometryImage2.Clip = this.myRectangleGeometry2;
34 | this.myText2.Clip = this.myTextRectangleGeometry;
35 | }
36 |
37 | private void Page_Unloaded(object sender, RoutedEventArgs e)
38 | {
39 | CompositionTarget.Rendering -= UpdateGeometry;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.字体动画效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void btnAni1_Click(object sender, RoutedEventArgs e)
29 | {
30 | bgFrame.Source = new Uri("/Pages/字体动画效果/Ani1.xaml", UriKind.RelativeOrAbsolute);
31 | }
32 |
33 | private void btnAni2_Click(object sender, RoutedEventArgs e)
34 | {
35 | bgFrame.Source = new Uri("/Pages/字体动画效果/Ani2.xaml", UriKind.RelativeOrAbsolute);
36 | }
37 |
38 | private void btnAni3_Click(object sender, RoutedEventArgs e)
39 | {
40 | bgFrame.Source = new Uri("/Pages/字体动画效果/Ani3.xaml", UriKind.RelativeOrAbsolute);
41 | }
42 |
43 | private void btnAni4_Click(object sender, RoutedEventArgs e)
44 | {
45 | bgFrame.Source = new Uri("/Pages/字体动画效果/Ani4.xaml", UriKind.RelativeOrAbsolute);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/MyImageControl.xaml:
--------------------------------------------------------------------------------
1 |
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 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/字体动画效果/MyImageControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Animation;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Media.Media3D;
15 | using System.Windows.Navigation;
16 | using System.Windows.Shapes;
17 |
18 | namespace WPF样式收集.Pages.字体动画效果
19 | {
20 | ///
21 | /// MyImageControl.xaml 的交互逻辑
22 | ///
23 | public partial class MyImageControl : UserControl
24 | {
25 | public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(String), typeof(MyImageControl), new PropertyMetadata(null));
26 | public String Text
27 | {
28 | get { return (String)GetValue(TextProperty); }
29 | set { SetValue(TextProperty, value); }
30 | }
31 |
32 | public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Brush), typeof(MyImageControl), new PropertyMetadata(null));
33 | public Brush TextColor
34 | {
35 | get { return (Brush)GetValue(TextColorProperty); }
36 | set { SetValue(TextColorProperty, value); }
37 | }
38 |
39 | public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register("Direction", typeof(String), typeof(MyImageControl), new PropertyMetadata(null));
40 | public String Direction
41 | {
42 | get { return (String)GetValue(DirectionProperty); }
43 | set { SetValue(DirectionProperty, value); }
44 | }
45 |
46 | private AxisAngleRotation3D aar;
47 | private RotateTransform3D rt;
48 |
49 | public MyImageControl()
50 | {
51 | InitializeComponent();
52 | this.Loaded += MyImageControl_Loaded;
53 | }
54 |
55 | private void MyImageControl_Loaded(object sender, RoutedEventArgs e)
56 | {
57 | rt = this.FindName("MyRotateTransform3D") as RotateTransform3D;
58 | aar = this.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D;
59 | switch (Direction)
60 | {
61 | case "Top":
62 | aar.Axis = new Vector3D(1, 0, 0);
63 | rt.CenterY = -10;
64 | break;
65 | case "Bottom":
66 | aar.Axis = new Vector3D(-1, 0, 0);
67 | rt.CenterY = 10;
68 | break;
69 | case "Left":
70 | aar.Axis = new Vector3D(0, 1, 0);
71 | rt.CenterX = 10;
72 | break;
73 | case "Right":
74 | aar.Axis = new Vector3D(0, -1, 0);
75 | rt.CenterX = -10;
76 | break;
77 | default:
78 | aar.Axis = new Vector3D(1, 0, 0);
79 | rt.CenterY = -10;
80 | break;
81 | }
82 | }
83 |
84 | private void Grid_MouseEnter(object sender, MouseEventArgs e)
85 | {
86 | aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, new DoubleAnimation(0, 20, new Duration(TimeSpan.FromMilliseconds(500))));
87 | }
88 |
89 | private void Grid_MouseLeave(object sender, MouseEventArgs e)
90 | {
91 | aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, new DoubleAnimation(20, 0, new Duration(TimeSpan.FromMilliseconds(500))));
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/悬停视差效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
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 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/悬停视差效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Animation;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Media.Media3D;
15 | using System.Windows.Navigation;
16 | using System.Windows.Shapes;
17 |
18 | namespace WPF样式收集.Pages.悬停视差效果
19 | {
20 | ///
21 | /// Index.xaml 的交互逻辑
22 | ///
23 | public partial class Index : Page
24 | {
25 | public Index()
26 | {
27 | InitializeComponent();
28 | }
29 |
30 | private void Image_MouseMove(object sender, MouseEventArgs e)
31 | {
32 | var moveX = (e.GetPosition(this.img).X / this.img.ActualWidth - 0.5) * (-25);
33 | var moveY = -(e.GetPosition(this.img).Y / this.img.ActualHeight - 0.5) * (-20);
34 |
35 | DoubleAnimation da = new DoubleAnimation();
36 | da.Duration = new Duration(TimeSpan.FromSeconds(1));
37 | da.To = 10d;
38 | Vector3D axis = new Vector3D(moveX, moveY, 0);
39 | AxisAngleRotation3D aar = this.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D;
40 | if (aar != null)
41 | {
42 | aar.Axis = axis;
43 | aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
44 | }
45 | }
46 |
47 | private void Image_MouseLeave(object sender, MouseEventArgs e)
48 | {
49 | DoubleAnimation da = new DoubleAnimation();
50 | da.Duration = new Duration(TimeSpan.FromSeconds(1));
51 | da.To = 0d;
52 | AxisAngleRotation3D aar = this.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D;
53 | if (aar != null)
54 | {
55 | aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/手风琴效果/Expander.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.手风琴效果
17 | {
18 | ///
19 | /// Expander.xaml 的交互逻辑
20 | ///
21 | public partial class Expander : UserControl
22 | {
23 | List itemList;
24 |
25 | public Expander()
26 | {
27 | InitializeComponent();
28 |
29 | itemList = new List();
30 | itemList.Add(new ExpanderClass("1", "/Resources/images1.jpg"));
31 | itemList.Add(new ExpanderClass("2", "/Resources/images1.jpg"));
32 | itemList.Add(new ExpanderClass("3", "/Resources/images1.jpg"));
33 | this.ExpanderItemBox.ItemsSource = itemList;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/手风琴效果/ExpanderClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WPF样式收集.Pages.手风琴效果
8 | {
9 | public class ExpanderClass
10 | {
11 | ///
12 | /// 标题
13 | ///
14 | public string Title { get; set; }
15 |
16 | ///
17 | /// 标题图片
18 | ///
19 | public string ImgUrl { get; set; }
20 |
21 | public ExpanderClass()
22 | {
23 | Title = string.Empty;
24 | ImgUrl = string.Empty;
25 | }
26 |
27 | public ExpanderClass(string t, string url)
28 | {
29 | Title = t;
30 | ImgUrl = url;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/手风琴效果/GridLengthAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Media.Animation;
8 |
9 | namespace WPF样式收集.Pages.手风琴效果
10 | {
11 | public class GridLengthAnimation : AnimationTimeline
12 | {
13 | static GridLengthAnimation()
14 | {
15 | FromProperty = DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation));
16 | ToProperty = DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation));
17 | }
18 |
19 | public static readonly DependencyProperty FromProperty;
20 | public GridLength From
21 | {
22 | get
23 | {
24 | return (GridLength)GetValue(GridLengthAnimation.FromProperty);
25 | }
26 | set
27 | {
28 | SetValue(GridLengthAnimation.FromProperty, value);
29 | }
30 | }
31 | public static readonly DependencyProperty ToProperty;
32 | public GridLength To
33 | {
34 | get
35 | {
36 | return (GridLength)GetValue(GridLengthAnimation.ToProperty);
37 | }
38 | set
39 | {
40 | SetValue(GridLengthAnimation.ToProperty, value);
41 | }
42 | }
43 |
44 | protected override System.Windows.Freezable CreateInstanceCore()
45 | {
46 | return new GridLengthAnimation();
47 | }
48 |
49 | public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
50 | {
51 | double fromVal = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value;
52 | double toVal = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value;
53 | if (fromVal > toVal)
54 | return new GridLength((1 - animationClock.CurrentProgress.Value) * (fromVal - toVal) + toVal, ((GridLength)GetValue(GridLengthAnimation.FromProperty)).GridUnitType);
55 | else
56 | return new GridLength(animationClock.CurrentProgress.Value * (toVal - fromVal) + fromVal, ((GridLength)GetValue(GridLengthAnimation.ToProperty)).GridUnitType);
57 | }
58 |
59 | public override Type TargetPropertyType
60 | {
61 | get
62 | {
63 | return typeof(GridLength);
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/手风琴效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/手风琴效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.手风琴效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 |
24 | public Index()
25 | {
26 | InitializeComponent();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/手风琴效果/MyGridControl.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/擦除效果/Index.xaml:
--------------------------------------------------------------------------------
1 |
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 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/擦除效果/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.擦除效果
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | PathGeometry gridGeometry = new PathGeometry();
24 |
25 | public Index()
26 | {
27 | InitializeComponent();
28 |
29 | RectangleGeometry rg = new RectangleGeometry();
30 | rg.Rect = new Rect(0, 0, this.Width, this.Height);
31 | gridGeometry = Geometry.Combine(gridGeometry, rg, GeometryCombineMode.Union, null);
32 | gridShadow.Clip = gridGeometry;
33 | CompositionTarget.Rendering += UpdateEllipseGeometry;
34 | }
35 |
36 | private void UpdateEllipseGeometry(object sender, EventArgs e)
37 | {
38 | EllipseGeometry rg = new EllipseGeometry();
39 | rg.Center = new Point(this.myEllipseGeometry.Transform.Value.OffsetX, this.myEllipseGeometry.Transform.Value.OffsetY);
40 | rg.RadiusX = this.myEllipseGeometry.RadiusX;
41 | rg.RadiusY = this.myEllipseGeometry.RadiusY;
42 | gridGeometry = Geometry.Combine(gridGeometry, rg, GeometryCombineMode.Exclude, null);
43 | gridShadow.Clip = gridGeometry;
44 | }
45 |
46 | private void Page_Unloaded(object sender, RoutedEventArgs e)
47 | {
48 | gridGeometry.Clear();
49 | CompositionTarget.Rendering -= UpdateEllipseGeometry;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/水珠效果按钮组/Index.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 | m 0 452.3622 656 -644.00002 644 644.00002 h -200 v 600 H 800 v -400 H 500 v 400 H 200 v -600 H 0 z
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/WPF样式收集/Pages/水珠效果按钮组/Index.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WPF样式收集.Pages.水珠效果按钮组
17 | {
18 | ///
19 | /// Index.xaml 的交互逻辑
20 | ///
21 | public partial class Index : Page
22 | {
23 | public Index()
24 | {
25 | InitializeComponent();
26 |
27 | Global.MainWindow.SetBugs("动画执行完全前被打断,将出现停滞,直到动画时间完成");
28 | }
29 |
30 | private void Page_Loaded(object sender, RoutedEventArgs e)
31 | {
32 | IList