NumericUpDownPage.xaml.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 ReactiveUI;
  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 : ReactiveObject
  26. {
  27. private IList<FormatObject> _formats;
  28. private FormatObject _selectedFormat;
  29. private IList<Location> _spinnerLocations;
  30. public NumbersPageViewModel()
  31. {
  32. SelectedFormat = Formats.FirstOrDefault();
  33. }
  34. public IList<FormatObject> Formats
  35. {
  36. get
  37. {
  38. return _formats ?? (_formats = new List<FormatObject>()
  39. {
  40. new FormatObject() {Name = "Currency", Value = "C2"},
  41. new FormatObject() {Name = "Fixed point", Value = "F2"},
  42. new FormatObject() {Name = "General", Value = "G"},
  43. new FormatObject() {Name = "Number", Value = "N"},
  44. new FormatObject() {Name = "Percent", Value = "P"},
  45. new FormatObject() {Name = "Degrees", Value = "{0:N2} °"},
  46. });
  47. }
  48. }
  49. public IList<Location> SpinnerLocations
  50. {
  51. get
  52. {
  53. if (_spinnerLocations == null)
  54. {
  55. _spinnerLocations = new List<Location>();
  56. foreach (Location value in Enum.GetValues(typeof(Location)))
  57. {
  58. _spinnerLocations.Add(value);
  59. }
  60. }
  61. return _spinnerLocations ;
  62. }
  63. }
  64. public IList<CultureInfo> Cultures { get; } = new List<CultureInfo>()
  65. {
  66. new CultureInfo("en-US"),
  67. new CultureInfo("en-GB"),
  68. new CultureInfo("fr-FR"),
  69. new CultureInfo("ar-DZ"),
  70. new CultureInfo("zh-CN"),
  71. new CultureInfo("cs-CZ")
  72. };
  73. public FormatObject SelectedFormat
  74. {
  75. get { return _selectedFormat; }
  76. set { this.RaiseAndSetIfChanged(ref _selectedFormat, value); }
  77. }
  78. }
  79. public class FormatObject
  80. {
  81. public string Value { get; set; }
  82. public string Name { get; set; }
  83. }
  84. }