MainWindow.xaml.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Notifications;
  4. using Avalonia.Controls.Primitives;
  5. using Avalonia.Markup.Xaml;
  6. using Avalonia.Threading;
  7. using ControlCatalog.ViewModels;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Threading.Tasks;
  11. namespace ControlCatalog
  12. {
  13. public class MainWindow : Window
  14. {
  15. private WindowNotificationManager _notificationArea;
  16. public MainWindow()
  17. {
  18. this.InitializeComponent();
  19. this.AttachDevTools();
  20. //Renderer.DrawFps = true;
  21. //Renderer.DrawDirtyRects = Renderer.DrawFps = true;
  22. _notificationArea = new WindowNotificationManager(this)
  23. {
  24. Position = NotificationPosition.TopRight,
  25. MaxItems = 3
  26. };
  27. DataContext = new MainWindowViewModel(_notificationArea);
  28. Dispatcher.UIThread.Post(() =>
  29. {
  30. new OpenFileDialog()
  31. {
  32. Filters = new List<FileDialogFilter>
  33. {
  34. new FileDialogFilter {Name = "All files", Extensions = {"*"}},
  35. new FileDialogFilter {Name = "Image files", Extensions = {"jpg", "png", "gif"}}
  36. },
  37. Directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  38. Title = "My dialog",
  39. InitialFileName = "config.local.json",
  40. AllowMultiple = true
  41. }.ShowAsync(this);
  42. });
  43. }
  44. private void InitializeComponent()
  45. {
  46. // TODO: iOS does not support dynamically loading assemblies
  47. // so we must refer to this resource DLL statically. For
  48. // now I am doing that here. But we need a better solution!!
  49. var theme = new Avalonia.Themes.Default.DefaultTheme();
  50. theme.TryGetResource("Button", out _);
  51. AvaloniaXamlLoader.Load(this);
  52. }
  53. }
  54. }