DialogsPage.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections.Generic;
  2. using Avalonia.Controls;
  3. using Avalonia.Markup.Xaml;
  4. #pragma warning disable 4014
  5. namespace ControlCatalog.Pages
  6. {
  7. public class DialogsPage : UserControl
  8. {
  9. public DialogsPage()
  10. {
  11. this.InitializeComponent();
  12. List<FileDialogFilter> GetFilters()
  13. {
  14. if (this.FindControl<CheckBox>("UseFilters").IsChecked != true)
  15. return null;
  16. return new List<FileDialogFilter>
  17. {
  18. new FileDialogFilter
  19. {
  20. Name = "Text files (.txt)", Extensions = new List<string> {"txt"}
  21. },
  22. new FileDialogFilter
  23. {
  24. Name = "All files",
  25. Extensions = new List<string> {"*"}
  26. }
  27. };
  28. }
  29. this.FindControl<Button>("OpenFile").Click += delegate
  30. {
  31. new OpenFileDialog()
  32. {
  33. Title = "Open file",
  34. Filters = GetFilters()
  35. }.ShowAsync(GetWindow());
  36. };
  37. this.FindControl<Button>("SaveFile").Click += delegate
  38. {
  39. new SaveFileDialog()
  40. {
  41. Title = "Save file",
  42. Filters = GetFilters()
  43. }.ShowAsync(GetWindow());
  44. };
  45. this.FindControl<Button>("SelectFolder").Click += delegate
  46. {
  47. new OpenFolderDialog()
  48. {
  49. Title = "Select folder"
  50. }.ShowAsync(GetWindow());
  51. };
  52. this.FindControl<Button>("DecoratedWindow").Click += delegate
  53. {
  54. new DecoratedWindow().Show();
  55. };
  56. this.FindControl<Button>("DecoratedWindowDialog").Click += delegate
  57. {
  58. new DecoratedWindow().ShowDialog(GetWindow());
  59. };
  60. this.FindControl<Button>("Dialog").Click += delegate
  61. {
  62. var window = new Window();
  63. window.Height = 200;
  64. window.Width = 200;
  65. window.Content = new TextBlock { Text = "Hello world!" };
  66. window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  67. window.ShowDialog(GetWindow());
  68. };
  69. }
  70. Window GetWindow() => (Window)this.VisualRoot;
  71. private void InitializeComponent()
  72. {
  73. AvaloniaXamlLoader.Load(this);
  74. }
  75. }
  76. }