ContentPageCustomizationPage.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Layout;
  4. using Avalonia.Media;
  5. namespace ControlCatalog.Pages
  6. {
  7. public partial class ContentPageCustomizationPage : UserControl
  8. {
  9. public ContentPageCustomizationPage()
  10. {
  11. InitializeComponent();
  12. }
  13. private void OnBackgroundChanged(object? sender, SelectionChangedEventArgs e)
  14. {
  15. if (SamplePage == null)
  16. return;
  17. SamplePage.Background = BackgroundCombo.SelectedIndex switch
  18. {
  19. 1 => new SolidColorBrush(Color.Parse("#E3F2FD")),
  20. 2 => new SolidColorBrush(Color.Parse("#E8F5E9")),
  21. 3 => new SolidColorBrush(Color.Parse("#F3E5F5")),
  22. 4 => new SolidColorBrush(Color.Parse("#FFF8E1")),
  23. _ => null
  24. };
  25. }
  26. private void OnHAlignChanged(object? sender, SelectionChangedEventArgs e)
  27. {
  28. if (SamplePage == null)
  29. return;
  30. SamplePage.HorizontalContentAlignment = HAlignCombo.SelectedIndex switch
  31. {
  32. 0 => HorizontalAlignment.Left,
  33. 1 => HorizontalAlignment.Center,
  34. 2 => HorizontalAlignment.Right,
  35. _ => HorizontalAlignment.Stretch
  36. };
  37. }
  38. private void OnVAlignChanged(object? sender, SelectionChangedEventArgs e)
  39. {
  40. if (SamplePage == null)
  41. return;
  42. SamplePage.VerticalContentAlignment = VAlignCombo.SelectedIndex switch
  43. {
  44. 0 => VerticalAlignment.Top,
  45. 1 => VerticalAlignment.Center,
  46. 2 => VerticalAlignment.Bottom,
  47. _ => VerticalAlignment.Stretch
  48. };
  49. }
  50. private void OnPaddingChanged(object? sender, Avalonia.Controls.Primitives.RangeBaseValueChangedEventArgs e)
  51. {
  52. if (SamplePage == null)
  53. return;
  54. var padding = (int)PaddingSlider.Value;
  55. SamplePage.Padding = new Avalonia.Thickness(padding);
  56. PaddingLabel.Text = $"{padding} px";
  57. }
  58. }
  59. }