diff --git a/src/Consolonia.Gallery/View/ControlsListView.axaml b/src/Consolonia.Gallery/View/ControlsListView.axaml index 60181320..5b4b2822 100644 --- a/src/Consolonia.Gallery/View/ControlsListView.axaml +++ b/src/Consolonia.Gallery/View/ControlsListView.axaml @@ -11,7 +11,7 @@ - @@ -19,21 +19,26 @@ Binding="{Binding Name}" /> - + - + + + + + + + \ No newline at end of file diff --git a/src/Consolonia.Gallery/View/ControlsListView.axaml.cs b/src/Consolonia.Gallery/View/ControlsListView.axaml.cs index 46073cfb..cbecca06 100644 --- a/src/Consolonia.Gallery/View/ControlsListView.axaml.cs +++ b/src/Consolonia.Gallery/View/ControlsListView.axaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Avalonia; using Avalonia.Controls; @@ -33,7 +34,7 @@ public ControlsListView() #if DEBUG this.AttachDevTools(); #endif - this.Grid.ItemsSource = _items = GalleryItem.Enumerated.ToArray(); + this.GalleryGrid.ItemsSource = _items = GalleryItem.Enumerated.ToArray(); var lifetime = Application.Current!.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime; if (lifetime != null) @@ -52,7 +53,7 @@ private void TrySetupSelected() { if (_commandLineArgs.Length is not 1 and not 2) { - this.Grid.SelectedIndex = 0; + this.GalleryGrid.SelectedIndex = 0; return; } @@ -72,8 +73,8 @@ private void TrySetupSelected() $"Several gallery items found with provided name {itemToSelectName}"); } - this.Grid.SelectedItem = itemToSelect; - this.Grid.Focus(); + this.GalleryGrid.SelectedItem = itemToSelect; + this.GalleryGrid.Focus(); } @@ -88,6 +89,20 @@ private void Exit_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) this.Close(); } + private async void OnShowXaml(object sender, Avalonia.Interactivity.RoutedEventArgs e) + { + var lifetime = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime; + + var selectedItem = GalleryGrid.SelectedItem as GalleryItem; + var path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Gallery", "GalleryViews", $"{selectedItem.Type.Name}.axaml")); + var dialog = new XamlDialogWindow() + { + DataContext = File.ReadAllText(path) + }; + + await dialog.ShowDialogAsync(lifetime.MainWindow); + } + private void ComboBox_SelectionChanged(object sender, Avalonia.Controls.SelectionChangedEventArgs e) { if (ThemeCombo?.SelectedItem is not ComboBoxItem selectedItem || diff --git a/src/Consolonia.Gallery/View/XamlDialogWindow.axaml b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml new file mode 100644 index 00000000..3b96bde5 --- /dev/null +++ b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs new file mode 100644 index 00000000..7d4cf23f --- /dev/null +++ b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs @@ -0,0 +1,35 @@ +using System.Linq; +using Avalonia; +using Avalonia.Input; +using Consolonia.Core.Controls; + +namespace Consolonia.Gallery.View +{ + public partial class XamlDialogWindow : DialogWindow + { + public XamlDialogWindow() + { + InitializeComponent(); + + AttachedToVisualTree += DialogWindowAttachedToVisualTree; + } + + private void DialogWindowAttachedToVisualTree(object sender, Avalonia.VisualTreeAttachmentEventArgs e) + { + AttachedToVisualTree -= DialogWindowAttachedToVisualTree; + + var child = this.LogicalChildren.FirstOrDefault(); + if (child is InputElement input) + input.AttachedToVisualTree += OnChildAttachedToVisualTree; + } + + private void OnChildAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e) + { + if (sender is InputElement input) + { + input.AttachedToVisualTree -= OnChildAttachedToVisualTree; + input.Focus(); + } + } + } +} \ No newline at end of file diff --git a/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs b/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs index 3b99f9f4..5e650db0 100644 --- a/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs +++ b/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs @@ -16,7 +16,7 @@ public async Task PerformSingleTest() await UITest.KeyInput(Key.Tab, RawInputModifiers.Shift); await UITest.KeyInput(Key.Tab, RawInputModifiers.Shift); await UITest.KeyInput(Key.PageDown); - await UITest.AssertHasText("Item 53"); + await UITest.AssertHasText("Item 49"); } } } \ No newline at end of file