跳到主要内容

github/tai

公开

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

浏览文件

Img.cs

94 行 · 2.9 KB历史下载
1using Core.Librarys.Image;
2using System;
3using System.Collections.Generic;
4using System.Diagnostics;
5using System.Drawing;
6using System.IO;
7using System.Linq;
8using System.Text;
9using System.Threading;
10using System.Threading.Tasks;
11using System.Windows;
12using System.Windows.Controls;
13using System.Windows.Data;
14using System.Windows.Documents;
15using System.Windows.Input;
16using System.Windows.Media;
17using System.Windows.Media.Imaging;
18using System.Windows.Navigation;
19using System.Windows.Shapes;
20using System.Windows.Threading;
21
22namespace UI.Controls.Base
23{
24 public class Img : Control
25 {
26 public CornerRadius Radius
27 {
28 get { return (CornerRadius)GetValue(RadiusProperty); }
29 set { SetValue(RadiusProperty, value); }
30 }
31 public static readonly DependencyProperty RadiusProperty =
32 DependencyProperty.Register("Radius",
33 typeof(CornerRadius),
34 typeof(Img));
35
36 public string Src
37 {
38 get { return (string)GetValue(SrcProperty); }
39 set { SetValue(SrcProperty, value); }
40 }
41 public static readonly DependencyProperty SrcProperty =
42 DependencyProperty.Register("Src",
43 typeof(string),
44 typeof(Img), new PropertyMetadata("pack://application:,,,/Tai;component/Resources/Icons/defaultIcon.png", new PropertyChangedCallback(OnPropertyChanged)));
45
46
47
48 /// <summary>
49 /// 图片链接
50 /// </summary>
51 public string URL
52 {
53 get { return (string)GetValue(URLProperty); }
54 set { SetValue(URLProperty, value); }
55 }
56 public static readonly DependencyProperty URLProperty =
57 DependencyProperty.Register("URL",
58 typeof(string),
59 typeof(Img), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));
60
61 private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
62 {
63 var control = (d as Img);
64 if (e.Property == URLProperty && e.OldValue != e.NewValue && e.NewValue != null)
65 {
66 control.Handle(e.NewValue.ToString());
67 }
68 }
69
70 public Img()
71 {
72 DefaultStyleKey = typeof(Img);
73 }
74
75 private void Handle(string path)
76 {
77 string defaultIconFile = "pack://application:,,,/Tai;component/Resources/Icons/defaultIcon.png";
78 if (string.IsNullOrEmpty(path))
79 {
80 Src = defaultIconFile;
81 return;
82 }
83 if (path.IndexOf("pack:") != -1)
84 {
85 Src = path;
86 return;
87 }
88
89 string src = path.IndexOf(":") != -1 ? path : System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
90 Src = File.Exists(src) ? src : defaultIconFile;
91 }
92
93 }
94}