| 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 | |
| 9 | namespace 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 | } |