├── .gitattributes
├── .gitignore
├── AntDesignSample
├── AntDesignSample.csproj
├── App.xaml
├── App.xaml.cs
├── AssemblyInfo.cs
├── MainWindow.xaml
└── MainWindow.xaml.cs
├── AntWpf.sln
├── AntWpf
├── AntWpf - Backup.csproj
├── AntWpf.csproj
├── Behaviors
│ ├── PasswordBoxBehavior.cs
│ ├── StylizedBehaviorCollection.cs
│ ├── StylizedBehaviors.cs
│ └── VisibilityBehavior.cs
├── ColorPalette.cs
├── Controls
│ ├── AntIcon.cs
│ ├── AntIconDataFactory.cs
│ ├── AntIconKey.cs
│ ├── Border.cs
│ ├── BorderStyle.cs
│ ├── Button.cs
│ ├── Helpers
│ │ ├── Control.cs
│ │ ├── Input.cs
│ │ ├── ProgressAssist.cs
│ │ └── TreeHelper.cs
│ ├── ISpinable.cs
│ ├── Icon.cs
│ ├── Shapes.cs
│ ├── Sizes.cs
│ ├── Switch.cs
│ └── Utils
│ │ ├── CornerRadiusUtil.cs
│ │ ├── DoubleUtil.cs
│ │ ├── DpiUtil.cs
│ │ ├── RectUtil.cs
│ │ ├── Spinner.cs
│ │ ├── ThicknessUtil.cs
│ │ └── UIElementUtil.cs
├── Converters
│ ├── ArcEndPointConverter.cs
│ ├── ArcSizeConverter.cs
│ ├── ArithmeticConverter.cs
│ ├── DoubleToCornerRadiusConverter.cs
│ ├── DoubleToThicknessMultiConverter.cs
│ ├── LessThanConverter.cs
│ ├── LocalEx.cs
│ ├── MathConverter.cs
│ ├── StartPointConverter.cs
│ ├── ThicknessReverseConverter.cs
│ └── ThicknessToDoubleConverter.cs
├── LICENSE.txt
├── README.md
├── Styles
│ ├── Animations.xaml
│ ├── AntIcon.xaml
│ ├── AntIcons.xaml
│ ├── CheckBox.xaml
│ ├── ComboBox.xaml
│ ├── Control.xaml
│ ├── Controls.xaml
│ ├── Input.xaml
│ ├── PasswordBox.xaml
│ ├── ProgressBar.xaml
│ ├── RadioButton.xaml
│ ├── Slider.xaml
│ ├── TextBox.xaml
│ └── Theme.xaml
├── Themes
│ ├── Button.xaml
│ └── Switch.xaml
├── ant_wpf.ico
├── images
│ ├── buttons.png
│ ├── check_radios.png
│ ├── icons.png
│ ├── inputs.png
│ ├── logos_ant-design.png
│ └── progress_bar.png
└── logos_ant-design.png
├── README.md
└── logos_ant-design.png
/.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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/AntDesignSample/AntDesignSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net6.0-windows
6 | enable
7 | true
8 | AnyCPU;x86
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/AntDesignSample/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/AntDesignSample/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 AntDesignSample
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AntDesignSample/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | [assembly: ThemeInfo(
4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5 | //(used if a resource is not found in the page,
6 | // or application resource dictionaries)
7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8 | //(used if a resource is not found in the page,
9 | // app, or any theme specific resource dictionaries)
10 | )]
11 |
--------------------------------------------------------------------------------
/AntDesignSample/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/AntDesignSample/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
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 | using AntWpf.Controls;
18 |
19 | namespace AntDesignSample
20 | {
21 | ///
22 | /// Interaction logic for MainWindow.xaml
23 | ///
24 | public partial class MainWindow : Window
25 | {
26 | public MainWindow()
27 | {
28 | InitializeComponent();
29 | }
30 | ObservableCollection iconsCollection = new();
31 | public override void OnApplyTemplate()
32 | {
33 | base.OnApplyTemplate();
34 |
35 |
36 | foreach (var animalValue in Enum.GetValues())
37 | {
38 | iconsCollection.Add(animalValue);
39 | }
40 | iconsList.ItemsSource = iconsCollection;
41 | }
42 |
43 |
44 | private void iconSearchBox_TextChanged(object sender, TextChangedEventArgs e)
45 | {
46 | var key = iconSearchBox.Text;
47 |
48 | var view = CollectionViewSource.GetDefaultView(iconsCollection);
49 |
50 | view.Filter = (o) =>
51 | {
52 | if (string.IsNullOrEmpty(key))
53 | return true;
54 |
55 | if (o is AntIconKey iconKey)
56 | {
57 | return iconKey.ToString().ToLower().Contains(key.ToLower());
58 | }
59 | return false;
60 | };
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/AntWpf.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33103.184
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntWpf", "AntWpf\AntWpf.csproj", "{3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntDesignSample", "AntDesignSample\AntDesignSample.csproj", "{E9120D98-63D7-4773-99C4-DFAB3F3D6450}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|x86 = Debug|x86
14 | Release|Any CPU = Release|Any CPU
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Debug|x86.ActiveCfg = Debug|x86
21 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Debug|x86.Build.0 = Debug|x86
22 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Release|x86.ActiveCfg = Release|x86
25 | {3742B06E-2FF9-4E45-9E0F-E6A5481D02B0}.Release|x86.Build.0 = Release|x86
26 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Debug|x86.ActiveCfg = Debug|x86
29 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Debug|x86.Build.0 = Debug|x86
30 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Release|x86.ActiveCfg = Release|x86
33 | {E9120D98-63D7-4773-99C4-DFAB3F3D6450}.Release|x86.Build.0 = Release|x86
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | GlobalSection(ExtensibilityGlobals) = postSolution
39 | SolutionGuid = {F33C3515-0B6F-4879-A59D-D3503A9A8C84}
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/AntWpf/AntWpf - Backup.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-windows
5 | enable
6 | true
7 | ant_wpf.ico
8 | True
9 | logos_ant-design.png
10 | https://github.com/Mumtozbekov/AntWpf
11 | MIT
12 | README.md
13 | 1.0.0.0
14 | 1.0.1
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | True
25 | \
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/AntWpf/AntWpf.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0.5
5 | AnyCPU;x86
6 |
7 |
8 |
9 | net6.0-windows
10 | enable
11 | true
12 | ant_wpf.ico
13 | True
14 | logos_ant-design.png
15 | https://github.com/Mumtozbekov/AntWpf
16 | README.md
17 | 1.0.2.0
18 | 1.0.2.0
19 | git
20 | MIT
21 | $(AssemblyName)Mumtozbekov
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | True
41 | \
42 |
43 |
44 | True
45 | \
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/AntWpf/Behaviors/PasswordBoxBehavior.cs:
--------------------------------------------------------------------------------
1 | namespace AntWpf.Behaviors
2 | {
3 | using AntWpf.Controls;
4 |
5 | using Microsoft.Xaml.Behaviors;
6 |
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Windows;
10 | using System.Windows.Controls;
11 | using System.Windows.Controls.Primitives;
12 | using System.Windows.Documents;
13 |
14 | [TemplatePart(Name = PART_TextBox, Type = typeof(TextBox))]
15 | [TemplatePart(Name = PART_Eye, Type = typeof(ToggleButton))]
16 | public class PasswordBoxBehavior : Behavior
17 | {
18 | #region Fields
19 |
20 | private const string PART_TextBox = "PART_TextBox";
21 |
22 | private const string PART_Eye = "PART_Eye";
23 |
24 | private static MethodInfo select;
25 |
26 | private static PropertyInfo selection;
27 |
28 | #endregion
29 |
30 | #region Private Attached Properties
31 |
32 | private static readonly DependencyProperty TextBoxProperty =
33 | DependencyProperty.RegisterAttached("TextBox", typeof(TextBox), typeof(PasswordBoxBehavior), new PropertyMetadata(null));
34 |
35 | private static TextBox GetTextBox(DependencyObject obj)
36 | {
37 | return (TextBox)obj.GetValue(TextBoxProperty);
38 | }
39 |
40 | private static void SetTextBox(DependencyObject obj, TextBox value)
41 | {
42 | obj.SetValue(TextBoxProperty, value);
43 | }
44 |
45 | #endregion
46 |
47 | #region Constructors
48 |
49 | static PasswordBoxBehavior()
50 | {
51 | select = typeof(PasswordBox).GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic);
52 | selection = typeof(PasswordBox).GetProperty("Selection", BindingFlags.NonPublic | BindingFlags.Instance);
53 | }
54 |
55 | #endregion
56 |
57 | #region Overrides
58 |
59 | protected override void OnAttached()
60 | {
61 | AssociatedObject.Loaded += OnLoaded;
62 | AssociatedObject.GotFocus += OnGotFocus;
63 | AssociatedObject.PasswordChanged += OnPasswordChanged;
64 |
65 | base.OnAttached();
66 | }
67 |
68 | protected override void OnDetaching()
69 | {
70 | AssociatedObject.Loaded -= OnLoaded;
71 | AssociatedObject.GotFocus -= OnGotFocus;
72 | AssociatedObject.PasswordChanged -= OnPasswordChanged;
73 |
74 | if (Input.GetEyeable(AssociatedObject))
75 | {
76 | AssociatedObject.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnEyeClick));
77 | }
78 |
79 | base.OnDetaching();
80 | }
81 |
82 | #endregion
83 |
84 | #region Private Methods
85 |
86 | ///
87 | /// Get the insertion position index of the caret.
88 | ///
89 | private static int GetCaretIndex(TextSelection selection)
90 | {
91 | if (selection == null) return 0;
92 |
93 | var tTextRange = selection.GetType().GetInterfaces().FirstOrDefault(i => i.Name == "ITextRange");
94 | var oStart = tTextRange?.GetProperty("Start")?.GetGetMethod()?.Invoke(selection, null);
95 | var value = oStart?.GetType().GetProperty("Offset", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(oStart, null) as int?;
96 |
97 | return value.GetValueOrDefault(0);
98 | }
99 |
100 | ///
101 | /// Set the insertion position index of the caret.
102 | ///
103 | private static void SetCaretIndex(object obj, int index)
104 | {
105 | select.Invoke(obj, new object[] { index, 0 });
106 | }
107 |
108 | private static void OnLoaded(object sender, RoutedEventArgs e)
109 | {
110 | var passwordBox = (PasswordBox)sender;
111 | var password = passwordBox.Password;
112 |
113 | if (!string.IsNullOrEmpty(password))
114 | {
115 | Input.SetPassword(passwordBox, password);
116 | SetCaretIndex(passwordBox, password.Length);
117 | }
118 |
119 | if (Input.GetEyeable(passwordBox))
120 | {
121 | SetTextBox(passwordBox, passwordBox.FindChild(PART_TextBox));
122 | passwordBox.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnEyeClick));
123 | }
124 | }
125 |
126 | private static void OnEyeClick(object sender, RoutedEventArgs e)
127 | {
128 | var passwordBox = (PasswordBox)sender;
129 | TextBox textBox;
130 |
131 | if (!(e.OriginalSource is ToggleButton button) || button.Name != PART_Eye ||
132 | (textBox = GetTextBox(passwordBox)) == null)
133 | {
134 | return;
135 | }
136 |
137 | e.Handled = true;
138 |
139 | if (button.IsChecked.GetValueOrDefault())
140 | {
141 | textBox.CaretIndex = GetCaretIndex(selection?.GetValue(passwordBox, null) as TextSelection);
142 | textBox.Focus();
143 | } else
144 | {
145 | SetCaretIndex(passwordBox, textBox.CaretIndex);
146 | passwordBox.Focus();
147 | }
148 | }
149 |
150 | private static void OnGotFocus(object sender, RoutedEventArgs e)
151 | {
152 | if (e.OriginalSource is PasswordBox passwordBox)
153 | {
154 | TextBox textBox;
155 |
156 | if (Input.GetEyeable(passwordBox) &&
157 | (textBox = GetTextBox(passwordBox)) != null &&
158 | textBox.Visibility == Visibility.Visible)
159 | {
160 | textBox.Focus();
161 | }
162 | }
163 | }
164 |
165 | private static void OnPasswordChanged(object sender, RoutedEventArgs e)
166 | {
167 | var passwordBox = (PasswordBox)sender;
168 | var password = passwordBox.Password;
169 |
170 | // Sync password
171 | if (password != Input.GetPassword(passwordBox))
172 | {
173 | Input.SetPassword(passwordBox, password);
174 | }
175 | }
176 |
177 | #endregion
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/AntWpf/Behaviors/StylizedBehaviorCollection.cs:
--------------------------------------------------------------------------------
1 | namespace AntWpf.Behaviors
2 | {
3 | using System.Windows;
4 |
5 | using Microsoft.Xaml.Behaviors;
6 |
7 | ///
8 | /// From https://github.com/MahApps/MahApps.Metro/tree/1.6.1/src/MahApps.Metro/Behaviours/StylizedBehaviorCollection.cs
9 | ///
10 | public class StylizedBehaviorCollection : FreezableCollection
11 | {
12 | protected override Freezable CreateInstanceCore()
13 | {
14 | return new StylizedBehaviorCollection();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AntWpf/Behaviors/StylizedBehaviors.cs:
--------------------------------------------------------------------------------
1 | namespace AntWpf.Behaviors
2 | {
3 | using System.Windows;
4 |
5 | using Microsoft.Xaml.Behaviors;
6 |
7 | ///
8 | /// From https://github.com/MahApps/MahApps.Metro/tree/1.6.1/src/MahApps.Metro/Behaviours/StylizedBehaviors.cs
9 | ///
10 | public class StylizedBehaviors
11 | {
12 | #region Properties
13 |
14 | public static readonly DependencyProperty BehaviorsProperty = DependencyProperty.RegisterAttached(
15 | "Behaviors",
16 | typeof(StylizedBehaviorCollection),
17 | typeof(StylizedBehaviors),
18 | new PropertyMetadata(null, OnBehaviorsChanged));
19 |
20 | public static StylizedBehaviorCollection GetBehaviors(DependencyObject obj)
21 | {
22 | return (StylizedBehaviorCollection)obj.GetValue(BehaviorsProperty);
23 | }
24 |
25 | public static void SetBehaviors(DependencyObject obj, StylizedBehaviorCollection value)
26 | {
27 | obj.SetValue(BehaviorsProperty, value);
28 | }
29 |
30 | public static readonly DependencyProperty OriginalBehaviorProperty = DependencyProperty.RegisterAttached(
31 | "OriginalBehavior",
32 | typeof(Behavior),
33 | typeof(StylizedBehaviors),
34 | new UIPropertyMetadata(null));
35 |
36 | public static Behavior GetOriginalBehavior(DependencyObject obj)
37 | {
38 | return (Behavior)obj.GetValue(OriginalBehaviorProperty);
39 | }
40 |
41 | public static void SetOriginalBehavior(DependencyObject obj, Behavior value)
42 | {
43 | obj.SetValue(OriginalBehaviorProperty, value);
44 | }
45 |
46 | #endregion
47 |
48 | #region Private Methods
49 |
50 | private static void OnBehaviorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
51 | {
52 | var fe = d as FrameworkElement;
53 | if (fe == null) return;
54 |
55 | var newVal = e.NewValue as StylizedBehaviorCollection;
56 | var oldVal = e.OldValue as StylizedBehaviorCollection;
57 |
58 | if (newVal == oldVal) return;
59 |
60 | var behaviors = Interaction.GetBehaviors(fe);
61 | fe.Unloaded -= OnUnloaded;
62 |
63 |
64 | if (oldVal != null)
65 | {
66 | foreach (var behavior in oldVal)
67 | {
68 | var index = GetIndexOf(behaviors, behavior);
69 | if (index >= 0)
70 | {
71 | behaviors.RemoveAt(index);
72 | }
73 | }
74 | }
75 |
76 | if (newVal != null)
77 | {
78 | foreach (var behavior in newVal)
79 | {
80 | var index = GetIndexOf(behaviors, behavior);
81 | if (index < 0)
82 | {
83 | var clone = (Behavior)behavior.Clone();
84 | SetOriginalBehavior(clone, behavior);
85 | behaviors.Add(clone);
86 | }
87 | }
88 | }
89 |
90 | if (behaviors.Count > 0)
91 | {
92 | fe.Unloaded += OnUnloaded;
93 | }
94 | }
95 |
96 | private static void OnLoaded(object sender, RoutedEventArgs e)
97 | {
98 | var fe = sender as FrameworkElement;
99 | if (fe == null) return;
100 |
101 | fe.Loaded -= OnLoaded;
102 | var behaviors = Interaction.GetBehaviors(fe);
103 |
104 | foreach (var behavior in behaviors)
105 | {
106 | behavior.Attach(fe);
107 | }
108 | }
109 |
110 | private static void OnUnloaded(object sender, RoutedEventArgs e)
111 | {
112 | var fe = sender as FrameworkElement;
113 | if (fe == null) return;
114 |
115 | var behaviors = Interaction.GetBehaviors(fe);
116 | foreach (var behavior in behaviors)
117 | {
118 | behavior.Detach();
119 | }
120 |
121 | fe.Loaded += OnLoaded;
122 | }
123 |
124 | private static int GetIndexOf(BehaviorCollection items, Behavior behavior)
125 | {
126 | int index = -1;
127 | var orignalBehavior = GetOriginalBehavior(behavior);
128 |
129 | for (int i = 0; i < items.Count; i++)
130 | {
131 | var currentBehavior = items[i];
132 | if (currentBehavior == behavior || currentBehavior == orignalBehavior)
133 | {
134 | index = i;
135 | break;
136 | }
137 |
138 | var currentOrignalBehavior = GetOriginalBehavior(currentBehavior);
139 | if (currentOrignalBehavior == behavior || currentOrignalBehavior == orignalBehavior)
140 | {
141 | index = i;
142 | break;
143 | }
144 | }
145 |
146 | return index;
147 | }
148 |
149 | #endregion
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/AntWpf/Behaviors/VisibilityBehavior.cs:
--------------------------------------------------------------------------------
1 | namespace Antd.Behaviors
2 | {
3 | using System.Windows;
4 | using System.Windows.Media.Animation;
5 |
6 | using Microsoft.Xaml.Behaviors;
7 |
8 | ///
9 | /// Provides the ability to animate when changing the Visibility property for an element.
10 | ///
11 | public class VisibilityBehavior : Behavior
12 | {
13 | #region Fields
14 |
15 | private Visibility visibility;
16 |
17 | #endregion
18 |
19 | #region Properties
20 |
21 | public static readonly DependencyProperty AppearProperty =
22 | DependencyProperty.Register("Appear", typeof(Storyboard), typeof(VisibilityBehavior), new PropertyMetadata(null));
23 |
24 | ///
25 | /// Gets/sets the storyboard when the element is visible.
26 | ///
27 | public Storyboard Appear
28 | {
29 | get { return (Storyboard)GetValue(AppearProperty); }
30 | set { SetValue(AppearProperty, value); }
31 | }
32 |
33 | public static readonly DependencyProperty LeaveProperty =
34 | DependencyProperty.Register("Leave", typeof(Storyboard), typeof(VisibilityBehavior), new PropertyMetadata(null));
35 |
36 | ///
37 | /// Gets/sets the storyboard when the element is hidden.
38 | ///
39 | public Storyboard Leave
40 | {
41 | get { return (Storyboard)GetValue(LeaveProperty); }
42 | set { SetValue(LeaveProperty, value); }
43 | }
44 |
45 | #endregion
46 |
47 | #region Overrides
48 |
49 | protected override void OnAttached()
50 | {
51 | visibility = AssociatedObject.Visibility;
52 | AssociatedObject.IsVisibleChanged += OnVisibleChanged;
53 |
54 | base.OnAttached();
55 | }
56 |
57 | private void OnLoaded(object sender, RoutedEventArgs e)
58 | {
59 | AssociatedObject.IsVisibleChanged += OnVisibleChanged;
60 | }
61 |
62 | protected override void OnDetaching()
63 | {
64 | AssociatedObject.IsVisibleChanged -= OnVisibleChanged;
65 |
66 | base.OnDetaching();
67 | }
68 |
69 | #endregion
70 |
71 | #region Private Methods
72 |
73 | private void OnVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
74 | {
75 | if (visibility == AssociatedObject.Visibility) return;
76 |
77 | Storyboard storyboard;
78 |
79 | if (AssociatedObject.Visibility == Visibility.Visible)
80 | {
81 | if (Appear == null) return;
82 |
83 | storyboard = Appear;
84 | visibility = AssociatedObject.Visibility;
85 |
86 | } else
87 | {
88 | if (Leave == null) return;
89 |
90 | var cache = AssociatedObject.Visibility;
91 | AssociatedObject.SetCurrentValue(UIElement.VisibilityProperty, visibility = Visibility.Visible);
92 |
93 | storyboard = Leave.Clone();
94 | storyboard.Completed += (s, a) => AssociatedObject.SetCurrentValue(UIElement.VisibilityProperty, visibility = cache);
95 | }
96 |
97 | AssociatedObject.BeginStoryboard(storyboard);
98 | }
99 |
100 | #endregion
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/AntWpf/ColorPalette.cs:
--------------------------------------------------------------------------------
1 | namespace AntWpf
2 | {
3 | using System;
4 | using System.Windows.Media;
5 |
6 | public static class ColorPalette
7 | {
8 | #region Fields
9 |
10 | private const int hueStep = 2;
11 |
12 | private const int saturationStep = 16;
13 |
14 | private const int saturationStep2 = 5;
15 |
16 | private const int brightnessStep1 = 5;
17 |
18 | private const int brightnessStep2 = 15;
19 |
20 | private const int lightColorCount = 5;
21 |
22 | private const int darkColorCount = 4;
23 |
24 | #endregion
25 |
26 | #region Public Methods
27 |
28 | public static Color Toning(Color color, int index)
29 | {
30 | bool isLight = index <= 6;
31 |
32 | HSV hsv = Color2Hsv(color);
33 | int i = isLight ? lightColorCount + 1 - index : index - lightColorCount - 1;
34 |
35 | return Hsv2Color(GetHue(hsv, i, isLight), GetSaturation(hsv, i, isLight), GetValue(hsv, i, isLight), color.A);
36 | }
37 |
38 | #endregion
39 |
40 | #region Private Methods
41 |
42 | private static double GetHue(HSV hsv, int i, bool isLight)
43 | {
44 | double hue;
45 |
46 | if (hsv.H >= 60 && hsv.H <= 240)
47 | {
48 | hue = isLight ? hsv.H - hueStep * i : hsv.H + hueStep * i;
49 | }
50 | else
51 | {
52 | hue = isLight ? hsv.H + hueStep * i : hsv.H - hueStep * i;
53 | }
54 |
55 | if (hue < 0)
56 | {
57 | hue += 360;
58 | }
59 | else if (hue >= 360)
60 | {
61 | hue -= 360;
62 | }
63 |
64 | return Math.Round(hue);
65 | }
66 | private static double GetSaturation(HSV hsv, int i, bool isLight)
67 | {
68 | double saturation;
69 |
70 | if (isLight)
71 | {
72 | saturation = Math.Round(hsv.S * 100) - saturationStep * i;
73 | }
74 | else if (i == darkColorCount)
75 | {
76 | saturation = Math.Round(hsv.S * 100) + saturationStep;
77 | }
78 | else
79 | {
80 | saturation = Math.Round(hsv.S * 100) + saturationStep2 * i;
81 | }
82 |
83 | if (saturation > 100)
84 | {
85 | saturation = 100;
86 | }
87 |
88 | if (isLight && i == lightColorCount && saturation > 10)
89 | {
90 | saturation = 10;
91 | }
92 |
93 | if (saturation < 6)
94 | {
95 | saturation = 6;
96 | }
97 |
98 | return Math.Round(saturation);
99 | }
100 |
101 | private static double GetValue(HSV hsv, int i, bool isLight)
102 | {
103 | if (isLight)
104 | {
105 | return Math.Round(hsv.V * 100) + brightnessStep1 * i;
106 | }
107 | return Math.Round(hsv.V * 100) - brightnessStep2 * i;
108 | }
109 |
110 | private static Color Hsv2Color(double h, double s, double v, byte a)
111 | {
112 | h = Bound(h, 360) * 6;
113 | s = Bound(s, 100);
114 | v = Bound(v, 100);
115 |
116 | double i = Math.Floor(h);
117 | double f = h - i;
118 |
119 | double p = v * (1 - s),
120 | q = v * (1 - f * s),
121 | t = v * (1 - (1 - f) * s);
122 |
123 | int mod = (int)(i % 6);
124 | double r = new double[6] { v, q, p, p, t, v }[mod],
125 | g = new double[6] { t, v, v, q, p, p }[mod],
126 | b = new double[6] { p, p, t, v, v, q }[mod];
127 |
128 | r = Math.Min(255, Math.Max(0, r * 255));
129 | g = Math.Min(255, Math.Max(0, g * 255));
130 | b = Math.Min(255, Math.Max(0, b * 255));
131 |
132 | return new Color() { R = (byte)Math.Round(r), G = (byte)Math.Round(g), B = (byte)Math.Round(b), A = a };
133 | }
134 |
135 | private static HSV Color2Hsv(Color color)
136 | {
137 | double r = Bound(color.R, 255),
138 | g = Bound(color.G, 255),
139 | b = Bound(color.B, 255);
140 |
141 | double max = Math.Max(r, Math.Max(g, b)),
142 | min = Math.Min(r, Math.Min(g, b));
143 |
144 | double h = 0,
145 | v = max,
146 | d = max - min;
147 | double s = max == 0 ? 0 : d / max;
148 |
149 | if (max != min)
150 | {
151 | if (max == r)
152 | {
153 | h = (g - b) / d + (g < b ? 6 : 0);
154 | }
155 | else if (max == g)
156 | {
157 | h = (b - r) / d + 2;
158 | }
159 | else if (max == b)
160 | {
161 | h = (r - g) / d + 4;
162 | }
163 |
164 | h /= 6;
165 | }
166 |
167 | return new HSV() { H = h * 360, S = s, V = v };
168 | }
169 |
170 | ///
171 | /// Take input from [0, n] and return it as [0, 1]
172 | ///
173 | ///
174 | ///
175 | ///
176 | private static double Bound(double n, double max)
177 | {
178 | n = Math.Min(max, Math.Max(0, n));
179 |
180 | // Handle floating point rounding errors
181 | if ((Math.Abs(n - max) < 0.000001))
182 | {
183 | return 1;
184 | }
185 |
186 | // Convert into [0, 1] range if it isn't already
187 | return (n % max) / max;
188 | }
189 |
190 | #endregion
191 | }
192 |
193 | internal struct HSV
194 | {
195 | public double H;
196 |
197 | public double S;
198 |
199 | public double V;
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/AntWpf/Controls/AntIcon.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System;
3 | using System.Windows;
4 | using System.Windows.Markup;
5 | using System.ComponentModel;
6 | using System.Windows.Media;
7 |
8 | namespace AntWpf.Controls
9 | {
10 | public class AntIcon : System.Windows.Controls.Control
11 | {
12 | private static readonly Lazy> _dataList
13 | = new Lazy>(AntIconDataFactory.Create);
14 |
15 | static AntIcon()
16 | {
17 | DefaultStyleKeyProperty.OverrideMetadata(typeof(AntIcon), new FrameworkPropertyMetadata(typeof(AntIcon)));
18 | }
19 |
20 | public static readonly DependencyProperty KeyProperty
21 | = DependencyProperty.Register(nameof(Key), typeof(AntIconKey), typeof(AntIcon), new PropertyMetadata(default(AntIconKey), KeyPropertyChangedCallback));
22 |
23 | private static void KeyPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
24 | => ((AntIcon)dependencyObject).UpdateData();
25 |
26 | private static readonly DependencyPropertyKey DataPropertyKey
27 | = DependencyProperty.RegisterReadOnly(nameof(Data), typeof(string), typeof(AntIcon), new PropertyMetadata(""));
28 |
29 | // ReSharper disable once StaticMemberInGenericType
30 | public static readonly DependencyProperty DataProperty = DataPropertyKey.DependencyProperty;
31 |
32 | ///
33 | /// Gets or sets the icon to display.
34 | ///
35 | public AntIconKey Key
36 | {
37 | get => (AntIconKey)GetValue(KeyProperty);
38 | set => SetValue(KeyProperty, value);
39 | }
40 |
41 |
42 | ///
43 | /// Gets the icon path data for the current .
44 | ///
45 | [TypeConverter(typeof(GeometryConverter))]
46 | public string? Data
47 | {
48 | get => (string?)GetValue(DataProperty);
49 | private set => SetValue(DataPropertyKey, value);
50 | }
51 | public override void OnApplyTemplate()
52 | {
53 | base.OnApplyTemplate();
54 | UpdateData();
55 | }
56 |
57 | private void UpdateData()
58 | {
59 | string? data = null;
60 | _dataList.Value?.TryGetValue(Key, out data);
61 | Data = data;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/AntWpf/Controls/BorderStyle.cs:
--------------------------------------------------------------------------------
1 | namespace AntWpf.Controls
2 | {
3 | public enum BorderStyle : byte
4 | {
5 | Solid, Dotted, Dashed
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/AntWpf/Controls/Button.cs:
--------------------------------------------------------------------------------
1 | namespace AntWpf.Controls
2 | {
3 | using System;
4 | using System.Windows;
5 | using System.Windows.Media;
6 | using System.Windows.Media.Animation;
7 | using System.Windows.Shapes;
8 | using ButtonBase = System.Windows.Controls.Button;
9 |
10 | ///
11 | /// To trigger an operation.
12 | ///
13 | [TemplatePart(Name = PART_Border, Type = typeof(FrameworkElement))]
14 | [TemplateVisualState(Name = "Loaded", GroupName = "LoadStates")]
15 | [TemplateVisualState(Name = "Unloaded", GroupName = "LoadStates")]
16 | public class Button : ButtonBase
17 | {
18 | #region Fields
19 |
20 | private const string PART_Border = "PART_Border";
21 |
22 | private FrameworkElement border;
23 |
24 | private VisualState mouseOverState;
25 |
26 | private VisualState pressedState;
27 |
28 | private VisualState focusedState;
29 |
30 | #endregion
31 |
32 | #region Properties
33 |
34 | public static readonly DependencyProperty GhostProperty =
35 | DependencyProperty.Register("Ghost", typeof(bool), typeof(Button), new PropertyMetadata(false, OnEffectBrushChanged));
36 |
37 | ///
38 | /// Gets/sets whether to make the background transparent and invert text and border colors.
39 | ///
40 | public bool Ghost
41 | {
42 | get { return (bool)GetValue(GhostProperty); }
43 | set { SetValue(GhostProperty, value); }
44 | }
45 |
46 | public static readonly DependencyProperty IconProperty =
47 | DependencyProperty.Register("Icon", typeof(string), typeof(Button), new PropertyMetadata(null));
48 |
49 | ///
50 | /// Gets/sets the icon type of the button.
51 | ///
52 | public string Icon
53 | {
54 | get { return (string)GetValue(IconProperty); }
55 | set { SetValue(IconProperty, value); }
56 | }
57 |
58 | public static readonly DependencyProperty LoadingProperty =
59 | DependencyProperty.Register("Loading", typeof(bool), typeof(Button), new PropertyMetadata(false, OnLoadingChanged));
60 |
61 | ///
62 | /// Gets/sets the loading state of the button.
63 | ///
64 | public bool Loading
65 | {
66 | get { return (bool)GetValue(LoadingProperty); }
67 | set { SetValue(LoadingProperty, value); }
68 | }
69 |
70 | private static void OnLoadingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
71 | {
72 | (d as Button).SetLoadVisualState();
73 | }
74 |
75 | private void SetLoadVisualState()
76 | {
77 | VisualStateManager.GoToState(this, (Loading ? "Loaded" : "Unloaded"), true);
78 | }
79 |
80 |
81 | public static readonly DependencyProperty ShapeProperty =
82 | DependencyProperty.Register("Shape", typeof(Shapes), typeof(Button), new PropertyMetadata(Shapes.Square));
83 |
84 | ///
85 | /// Gets/sets the shape of button.
86 | ///
87 | public Shapes Shape
88 | {
89 | get { return (Shapes)GetValue(ShapeProperty); }
90 | set { SetValue(ShapeProperty, value); }
91 | }
92 |
93 | public static readonly DependencyProperty SizeProperty =
94 | DependencyProperty.Register("Size", typeof(Sizes?), typeof(Button), new PropertyMetadata(null));
95 |
96 | ///
97 | /// Gets/sets the size of the button.
98 | ///
99 | public Sizes? Size
100 | {
101 | get { return (Sizes?)GetValue(SizeProperty); }
102 | set { SetValue(SizeProperty, value); }
103 | }
104 |
105 | public static readonly DependencyProperty TypeProperty =
106 | DependencyProperty.Register("Type", typeof(ButtonType?), typeof(Button), new PropertyMetadata(null));
107 |
108 | ///
109 | /// Gets/sets the type of the button.
110 | ///
111 | public ButtonType? Type
112 | {
113 | get { return (ButtonType?)GetValue(TypeProperty); }
114 | set { SetValue(TypeProperty, value); }
115 | }
116 |
117 | public static readonly DependencyProperty EffectBrushProperty = DependencyProperty.Register(
118 | "EffectBrush",
119 | typeof(Brush),
120 | typeof(Button),
121 | new FrameworkPropertyMetadata(
122 | Brushes.Transparent,
123 | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits,
124 | OnEffectBrushChanged));
125 |
126 | ///
127 | /// Gets/sets the border effect brush of the button.
128 | ///
129 | public Brush EffectBrush
130 | {
131 | get { return (Brush)GetValue(EffectBrushProperty); }
132 | set { SetValue(EffectBrushProperty, value); }
133 | }
134 |
135 | private static void OnEffectBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
136 | {
137 | (d as Button).SetVisualStateAnimation();
138 | }
139 |
140 | ///
141 | /// Force background transparent in Ghost state.
142 | ///
143 | private static object OnBackgroundCoerceValue(DependencyObject d, object baseValue)
144 | {
145 | var button = d as Button;
146 |
147 | if (button.Ghost)
148 | {
149 | return Brushes.Transparent;
150 | }
151 |
152 | return baseValue;
153 | }
154 |
155 | #endregion
156 |
157 | #region Constructors
158 |
159 | static Button()
160 | {
161 | DefaultStyleKeyProperty.OverrideMetadata(typeof(Button), new FrameworkPropertyMetadata(typeof(Button)));
162 | BackgroundProperty.OverrideMetadata(typeof(Button), new FrameworkPropertyMetadata { CoerceValueCallback = OnBackgroundCoerceValue });
163 | }
164 |
165 | #endregion
166 |
167 | #region Overrides
168 |
169 | public override void OnApplyTemplate()
170 | {
171 | base.OnApplyTemplate();
172 |
173 | border = GetTemplateChild(PART_Border) as FrameworkElement;
174 | mouseOverState = GetTemplateChild("MouseOver") as VisualState;
175 |
176 | focusedState = GetTemplateChild("Focused") as VisualState;
177 | pressedState = GetTemplateChild("Pressed") as VisualState;
178 |
179 | SetVisualStateAnimation();
180 | SetLoadVisualState();
181 | }
182 |
183 | #endregion
184 |
185 | #region Private Methods
186 |
187 | private void SetVisualStateAnimation()
188 | {
189 | // No initialization or no need for me to handle.
190 | if (border == null || mouseOverState == null && focusedState == null && pressedState == null) return;
191 |
192 | // Unable to extract color.
193 | if (EffectBrush is SolidColorBrush brush)
194 | {
195 | var isShape = border is Shape;
196 | Func