NumericUpDownPage.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using Avalonia;
  6. using Avalonia.Controls;
  7. using Avalonia.Controls.Primitives;
  8. using Avalonia.Markup.Xaml;
  9. using MiniMvvm;
  10. namespace ControlCatalog.Pages
  11. {
  12. public class NumericUpDownPage : UserControl
  13. {
  14. public NumericUpDownPage()
  15. {
  16. this.InitializeComponent();
  17. var viewModel = new NumbersPageViewModel();
  18. DataContext = viewModel;
  19. }
  20. private void InitializeComponent()
  21. {
  22. AvaloniaXamlLoader.Load(this);
  23. }
  24. }
  25. public class NumbersPageViewModel : ViewModelBase
  26. {
  27. private IList<FormatObject> _formats;
  28. private FormatObject _selectedFormat;
  29. private IList<Location> _spinnerLocations;
  30. private double _doubleValue;
  31. private decimal _decimalValue;
  32. public NumbersPageViewModel()
  33. {
  34. SelectedFormat = Formats.FirstOrDefault();
  35. }
  36. public double DoubleValue
  37. {
  38. get { return _doubleValue; }
  39. set { this.RaiseAndSetIfChanged(ref _doubleValue, value); }
  40. }
  41. public decimal DecimalValue
  42. {
  43. get { return _decimalValue; }
  44. set { this.RaiseAndSetIfChanged(ref _decimalValue, value); }
  45. }
  46. public IList<FormatObject> Formats
  47. {
  48. get
  49. {
  50. return _formats ?? (_formats = new List<FormatObject>()
  51. {
  52. new FormatObject() {Name = "Currency", Value = "C2"},
  53. new FormatObject() {Name = "Fixed point", Value = "F2"},
  54. new FormatObject() {Name = "General", Value = "G"},
  55. new FormatObject() {Name = "Number", Value = "N"},
  56. new FormatObject() {Name = "Percent", Value = "P"},
  57. new FormatObject() {Name = "Degrees", Value = "{0:N2} °"},
  58. });
  59. }
  60. }
  61. public IList<Location> SpinnerLocations
  62. {
  63. get
  64. {
  65. if (_spinnerLocations == null)
  66. {
  67. _spinnerLocations = new List<Location>();
  68. foreach (Location value in Enum.GetValues(typeof(Location)))
  69. {
  70. _spinnerLocations.Add(value);
  71. }
  72. }
  73. return _spinnerLocations ;
  74. }
  75. }
  76. public IList<CultureInfo> Cultures { get; } = new List<CultureInfo>()
  77. {
  78. new CultureInfo("en-US"),
  79. new CultureInfo("en-GB"),
  80. new CultureInfo("fr-FR"),
  81. new CultureInfo("ar-DZ"),
  82. new CultureInfo("zh-CN"),
  83. new CultureInfo("cs-CZ")
  84. };
  85. public FormatObject SelectedFormat
  86. {
  87. get { return _selectedFormat; }
  88. set { this.RaiseAndSetIfChanged(ref _selectedFormat, value); }
  89. }
  90. }
  91. public class FormatObject
  92. {
  93. public string Value { get; set; }
  94. public string Name { get; set; }
  95. }
  96. }