Added query submitted event to handle default action on clicking a list view item

This commit is contained in:
Divyansh
2020-04-06 16:08:31 -07:00
parent abbaca3c71
commit 553922bef6
2 changed files with 17 additions and 7 deletions

View File

@@ -422,7 +422,7 @@
<SymbolIcon Symbol="Find"/>
</AutoSuggestBox.QueryIcon>
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<DataTemplate >
<Grid Height="72" Width="690" Background="Transparent" RowSpacing="0">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="PointerEntered">
@@ -442,7 +442,7 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image x:Name="AppIcon" Height="36" Margin="8,0,0,0" Grid.RowSpan="2" HorizontalAlignment="Left" />
<Image x:Name="AppIcon" Height="36" Margin="8,0,0,0" Grid.RowSpan="2" HorizontalAlignment="Left" Source="{Binding Result.IcoPath}" />
<TextBlock x:Name="Title" Grid.Column="1" Text="{Binding Result.Title}" FontWeight="SemiBold" FontSize="20" VerticalAlignment="Bottom"/>
<TextBlock x:Name="Path" Grid.Column="1" Text="C:\Program Files\WindowsApps\Microsoft\Folder " Grid.Row="1" Opacity="0.6" VerticalAlignment="Top"/>
<StackPanel Orientation="Horizontal" Opacity="0" HorizontalAlignment="Right" Grid.RowSpan="2" Grid.Column="1">

View File

@@ -20,6 +20,7 @@ using Microsoft.Toolkit.Wpf.UI.XamlHost;
using Windows.UI.Xaml.Controls;
using System.Diagnostics;
using Wox.Plugin;
using Windows.UI.Xaml.Input;
namespace PowerLauncher
{
@@ -260,9 +261,9 @@ namespace PowerLauncher
_launcher = (PowerLauncher.UI.LauncherControl)host.Child;
_launcher.DataContext = _viewModel;
_launcher.SearchBox.TextChanged += QueryTextBox_TextChanged;
_launcher.SearchBox.SuggestionChosen += SearchBox_SuggestionChosen;
_launcher.SearchBox.SuggestionChosen += AutoSuggestBox_SuggestionChosen;
_launcher.SearchBox.QuerySubmitted += AutoSuggestBox_QuerySubmitted;
_launcher.SearchBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
_viewModel.PropertyChanged += (o, e) =>
{
if (e.PropertyName == nameof(MainViewModel.MainWindowVisibility))
@@ -282,12 +283,21 @@ namespace PowerLauncher
};
}
private void SearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
if (args != null)
if(args != null && args.SelectedItem != null)
{
ResultViewModel result = (ResultViewModel)args.SelectedItem;
_ = result.Result.Action != null && result.Result.Action(new ActionContext{});
sender.Text = result.Result.Title;
}
}
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (args != null && args.ChosenSuggestion != null)
{
ResultViewModel result = (ResultViewModel)args.ChosenSuggestion;
_ = result.Result.Action != null && result.Result.Action(new ActionContext { });
}
}