Added callback function for mouse click on search result

This commit is contained in:
Divyansh 2020-04-02 18:08:02 -07:00
parent d73ab36dc3
commit b6f927c454
3 changed files with 15 additions and 3 deletions

View File

@ -418,7 +418,7 @@
<AutoSuggestBox x:Name="SearchBox" x:FieldModifier="public" PlaceholderText="Launch an app" FontSize="24" Style="{StaticResource CustomStyledAutoSuggestBox}" MinWidth="720"
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Results.Results}">
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Results.Results}">
<AutoSuggestBox.QueryIcon>
<SymbolIcon Symbol="Find"/>
</AutoSuggestBox.QueryIcon>

View File

@ -18,6 +18,7 @@ using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using Windows.UI.Xaml.Controls;
using System.Diagnostics;
namespace PowerLauncher
{
@ -133,6 +134,8 @@ namespace PowerLauncher
// }
//}
private void OnDrop(object sender, DragEventArgs e)
{
@ -256,7 +259,7 @@ namespace PowerLauncher
_launcher = (PowerLauncher.UI.LauncherControl)host.Child;
_launcher.DataContext = _viewModel;
_launcher.SearchBox.TextChanged += QueryTextBox_TextChanged;
_launcher.SearchBox.SuggestionChosen += SearchBox_SuggestionChosen;
_launcher.SearchBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
_viewModel.PropertyChanged += (o, e) =>
@ -277,6 +280,16 @@ namespace PowerLauncher
}
};
}
private void SearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
if (args != null)
{
ResultViewModel result = (ResultViewModel)args.SelectedItem;
Process.Start(result.Result.SubTitle);
}
}
private void QueryTextBox_TextChanged(Windows.UI.Xaml.Controls.AutoSuggestBox sender, Windows.UI.Xaml.Controls.AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)

View File

@ -66,6 +66,5 @@ namespace Wox.ViewModel
{
return Result.ToString();
}
}
}