Bläddra i källkod

Avalonia: Added "SearchOnChanged" to SearchBar

Kenric Nugteren 4 månader sedan
förälder
incheckning
29b481f85e

+ 3 - 0
InABox.Avalonia/Components/SearchBar/SearchBar.axaml

@@ -30,6 +30,9 @@
 					 Margin="0"
 					 BorderBrush="Transparent"
 					 BorderThickness="0">
+				<TextBox.KeyBindings>
+					<KeyBinding Command="{Binding $parent[components:SearchBar].Command}" Gesture="Enter"/>
+				</TextBox.KeyBindings>
 			</TextBox>
 		</Grid>
 	</Border>

+ 10 - 1
InABox.Avalonia/Components/SearchBar/SearchBar.axaml.cs

@@ -35,6 +35,15 @@ public partial class SearchBar : UserControl
         set => SetValue(TextProperty, value);
     }
 
+    public static readonly StyledProperty<bool> SearchOnChangedProperty =
+        AvaloniaProperty.Register<SearchBar, bool>(nameof(SearchOnChanged), true);
+
+    public bool SearchOnChanged
+    {
+        get => GetValue(SearchOnChangedProperty);
+        set => SetValue(SearchOnChangedProperty, value);
+    }
+
     public SearchBar()
     {
         InitializeComponent();
@@ -42,7 +51,7 @@ public partial class SearchBar : UserControl
 
     private void TextBox_TextChanged(object? sender, TextChangedEventArgs e)
     {
-        if (Command is not null && Command.CanExecute(null))
+        if (SearchOnChanged && Command is not null && Command.CanExecute(null))
         {
             Command.Execute(null);
         }