跳到主要内容

github/tai

公开

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

浏览文件

ImageSelect.cs

85 行 · 2.7 KB历史下载
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.Windows;
7using System.Windows.Controls;
8
9namespace UI.Controls.Select
10{
11 public class ImageSelect : Control
12 {
13 public string URL
14 {
15 get { return (string)GetValue(URLProperty); }
16 set { SetValue(URLProperty, value); }
17 }
18 public static readonly DependencyProperty URLProperty =
19 DependencyProperty.Register("URL",
20 typeof(string),
21 typeof(ImageSelect), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));
22
23 private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
24 {
25 var control = d as ImageSelect;
26 if (e.Property == URLProperty)
27 {
28 control.IsSelected = !string.IsNullOrEmpty(control.URL);
29 }
30 }
31
32 public bool IsSelected
33 {
34 get { return (bool)GetValue(IsSelectedProperty); }
35 set { SetValue(IsSelectedProperty, value); }
36 }
37 public static readonly DependencyProperty IsSelectedProperty =
38 DependencyProperty.Register("IsSelected",
39 typeof(bool),
40 typeof(ImageSelect), new PropertyMetadata(false));
41
42 public double ImageWidth
43 {
44 get { return (double)GetValue(ImageWidthProperty); }
45 set { SetValue(ImageWidthProperty, value); }
46 }
47 public static readonly DependencyProperty ImageWidthProperty =
48 DependencyProperty.Register("ImageWidth",
49 typeof(double),
50 typeof(ImageSelect), new PropertyMetadata((double)30));
51
52 public double ImageHeight
53 {
54 get { return (double)GetValue(ImageHeightProperty); }
55 set { SetValue(ImageHeightProperty, value); }
56 }
57 public static readonly DependencyProperty ImageHeightProperty =
58 DependencyProperty.Register("ImageHeight",
59 typeof(double),
60 typeof(ImageSelect), new PropertyMetadata((double)30));
61 public Command SelectCommand { get; set; }
62 public ImageSelect()
63 {
64 DefaultStyleKey = typeof(ImageSelect);
65 SelectCommand = new Command(new Action<object>(OnSelect));
66 }
67
68 private void OnSelect(object obj)
69 {
70 Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
71
72
73 dlg.Filter = "PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg";
74
75
76 bool? result = dlg.ShowDialog();
77
78
79 if (result == true)
80 {
81 URL = dlg.FileName;
82 }
83 }
84 }
85}