TabControlPage.xaml.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using Avalonia;
  3. using Avalonia.Controls;
  4. using Avalonia.Markup.Xaml;
  5. using Avalonia.Media.Imaging;
  6. using Avalonia.Platform;
  7. using ControlCatalog.ViewModels;
  8. namespace ControlCatalog.Pages
  9. {
  10. using System.Collections.Generic;
  11. public class TabControlPage : UserControl
  12. {
  13. public TabControlPage()
  14. {
  15. InitializeComponent();
  16. DataContext = new TabControlPageViewModel
  17. {
  18. Tabs = new[]
  19. {
  20. new TabControlPageViewModelItem
  21. {
  22. Header = "Arch",
  23. Text = "This is the first templated tab page.",
  24. Image = LoadBitmap("avares://ControlCatalog/Assets/delicate-arch-896885_640.jpg"),
  25. },
  26. new TabControlPageViewModelItem
  27. {
  28. Header = "Leaf",
  29. Text = "This is the second templated tab page.",
  30. Image = LoadBitmap("avares://ControlCatalog/Assets/maple-leaf-888807_640.jpg"),
  31. },
  32. new TabControlPageViewModelItem
  33. {
  34. Header = "Disabled",
  35. Text = "You should not see this.",
  36. IsEnabled = false,
  37. },
  38. },
  39. TabPlacement = Dock.Top,
  40. };
  41. }
  42. private void InitializeComponent()
  43. {
  44. AvaloniaXamlLoader.Load(this);
  45. }
  46. private static IBitmap LoadBitmap(string uri)
  47. {
  48. var assets = AvaloniaLocator.Current!.GetService<IAssetLoader>()!;
  49. return new Bitmap(assets.Open(new Uri(uri)));
  50. }
  51. }
  52. }