mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
Fixed initial focus on WPF issue (#4113)
* Fixed initial focus on WPF issue * Added comment for property change * Updated function naming for visibility callback
This commit is contained in:
committed by
GitHub
parent
b574d4e388
commit
93af4fc6b0
@@ -21,6 +21,7 @@
|
||||
Background="Transparent"
|
||||
LocationChanged="OnLocationChanged"
|
||||
Deactivated="OnDeactivated"
|
||||
IsVisibleChanged="OnVisibilityChanged"
|
||||
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
||||
<Window.Resources>
|
||||
|
||||
@@ -78,6 +78,8 @@ namespace PowerLauncher
|
||||
ListBox.SuggestionsList.SelectionChanged += SuggestionsList_SelectionChanged;
|
||||
ListBox.SuggestionsList.PreviewMouseLeftButtonUp += SuggestionsList_PreviewMouseLeftButtonUp;
|
||||
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
|
||||
Activate();
|
||||
}
|
||||
|
||||
private void SuggestionsList_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
@@ -98,32 +100,16 @@ namespace PowerLauncher
|
||||
|
||||
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(MainViewModel.MainWindowVisibility))
|
||||
if (Visibility == System.Windows.Visibility.Visible)
|
||||
{
|
||||
if (Visibility == System.Windows.Visibility.Visible)
|
||||
// Not called on first launch
|
||||
// Additionally called when deactivated by clicking on screen
|
||||
UpdatePosition();
|
||||
Activate();
|
||||
|
||||
if (!_viewModel.LastQuerySelected)
|
||||
{
|
||||
_deletePressed = false;
|
||||
_firstDeleteTimer.Start();
|
||||
Activate();
|
||||
//(this.FindResource("IntroStoryboard") as Storyboard).Begin();
|
||||
|
||||
UpdatePosition();
|
||||
SearchBox.QueryTextBox.Focus();
|
||||
_settings.ActivateTimes++;
|
||||
|
||||
if (!_viewModel.LastQuerySelected)
|
||||
{
|
||||
_viewModel.LastQuerySelected = true;
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(SearchBox.QueryTextBox.Text))
|
||||
{
|
||||
SearchBox.QueryTextBox.SelectAll();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_firstDeleteTimer.Stop();
|
||||
_viewModel.LastQuerySelected = true;
|
||||
}
|
||||
}
|
||||
else if (e.PropertyName == nameof(MainViewModel.SystemQueryText))
|
||||
@@ -331,9 +317,28 @@ namespace PowerLauncher
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
private void OnVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Changed");
|
||||
if (Visibility == Visibility.Visible)
|
||||
{
|
||||
_deletePressed = false;
|
||||
_firstDeleteTimer.Start();
|
||||
// (this.FindResource("IntroStoryboard") as Storyboard).Begin();
|
||||
|
||||
SearchBox.QueryTextBox.Focus();
|
||||
Keyboard.Focus(SearchBox.QueryTextBox);
|
||||
|
||||
_settings.ActivateTimes++;
|
||||
|
||||
if (!String.IsNullOrEmpty(SearchBox.QueryTextBox.Text))
|
||||
{
|
||||
SearchBox.QueryTextBox.SelectAll();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_firstDeleteTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void OutroStoryboard_Completed(object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user