跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

浏览文件

IconButton.cs

71 行 · 2.3 KB历史下载
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.Windows;
7using System.Windows.Controls;
8using System.Windows.Input;
9using UI.Controls.Base;
10
11namespace UI.Controls.Button
12{
13 public class IconButton : ContentControl
14 {
15 public ICommand Command
16 {
17 get { return (ICommand)GetValue(CommandProperty); }
18 set { SetValue(CommandProperty, value); }
19 }
20 public static readonly DependencyProperty CommandProperty =
21 DependencyProperty.Register("Command",
22 typeof(ICommand),
23 typeof(IconButton));
24
25 public object CommandParameter
26 {
27 get { return (object)GetValue(CommandParameterProperty); }
28 set { SetValue(CommandParameterProperty, value); }
29 }
30 public static readonly DependencyProperty CommandParameterProperty =
31 DependencyProperty.Register("CommandParameter",
32 typeof(object),
33 typeof(IconButton));
34 public IconTypes Icon
35 {
36 get { return (IconTypes)GetValue(IconProperty); }
37 set { SetValue(IconProperty, value); }
38 }
39 public static readonly DependencyProperty IconProperty =
40 DependencyProperty.Register("Icon",
41 typeof(IconTypes),
42 typeof(IconButton), new PropertyMetadata(IconTypes.None));
43 public IconButton()
44 {
45 DefaultStyleKey = typeof(IconButton);
46 }
47
48 protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
49 {
50 base.OnMouseLeftButtonUp(e);
51 VisualStateManager.GoToState(this, "MouseOver", true);
52
53 Command?.Execute(CommandParameter);
54 }
55 protected override void OnMouseEnter(MouseEventArgs e)
56 {
57 base.OnMouseEnter(e);
58 VisualStateManager.GoToState(this, "MouseOver", true);
59 }
60 protected override void OnMouseLeave(MouseEventArgs e)
61 {
62 base.OnMouseLeave(e);
63 VisualStateManager.GoToState(this, "Normal", true);
64 }
65 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
66 {
67 base.OnMouseLeftButtonDown(e);
68 VisualStateManager.GoToState(this, "Pressed", true);
69 }
70 }
71}