MatrixRadioControl.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace Compdfkit_Tools.Common
  18. {
  19. /// <summary>
  20. /// Interaction logic for MetrixRadioControl.xaml
  21. /// </summary>
  22. public partial class MatrixRadioControl : UserControl, INotifyPropertyChanged
  23. {
  24. public static readonly DependencyProperty SelectedTagProperty =
  25. DependencyProperty.Register("SelectedTag", typeof(int), typeof(MatrixRadioControl), new PropertyMetadata(4));
  26. public int SelectedTag
  27. {
  28. get { return (int)GetValue(SelectedTagProperty); }
  29. set
  30. {
  31. SetValue(SelectedTagProperty, value);
  32. }
  33. }
  34. private int _selectedTagValue = 4;
  35. public int SelectedTagValue
  36. {
  37. get => _selectedTagValue;
  38. set
  39. {
  40. if (UpdateProper(ref _selectedTagValue, value))
  41. {
  42. SelectedTag = value;
  43. }
  44. }
  45. }
  46. public MatrixRadioControl()
  47. {
  48. InitializeComponent();
  49. }
  50. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  51. {
  52. var rdo = sender as RadioButton;
  53. SelectedTagValue = int.Parse((string)rdo.Tag);
  54. }
  55. public event PropertyChangedEventHandler PropertyChanged;
  56. protected virtual void OnPropertyChanged(string propertyName = null)
  57. {
  58. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  59. }
  60. protected bool UpdateProper<T>(ref T properValue,
  61. T newValue,
  62. [CallerMemberName] string properName = "")
  63. {
  64. if (object.Equals(properValue, newValue))
  65. return false;
  66. properValue = newValue;
  67. OnPropertyChanged(properName);
  68. return true;
  69. }
  70. }
  71. }