[Quick Accent]Fix the first character selection in the toolbar (#22808)

This commit is contained in:
Taras 2022-12-16 11:36:55 +02:00 committed by GitHub
parent 57bde1c54c
commit 0de7781b51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,14 +3,9 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Unicode;
using System.Windows; using System.Windows;
using PowerAccent.Core.Services; using PowerAccent.Core.Services;
using PowerToys.PowerAccentKeyboardService;
using Point = PowerAccent.Core.Point; using Point = PowerAccent.Core.Point;
using Size = PowerAccent.Core.Size; using Size = PowerAccent.Core.Size;
@ -22,6 +17,8 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
private Visibility _characterNameVisibility = Visibility.Visible; private Visibility _characterNameVisibility = Visibility.Visible;
private int _selectedIndex = 0;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public Visibility CharacterNameVisibility public Visibility CharacterNameVisibility
@ -55,9 +52,9 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
private void PowerAccent_OnSelectionCharacter(int index, string character) private void PowerAccent_OnSelectionCharacter(int index, string character)
{ {
characters.SelectedIndex = index; _selectedIndex = index;
characters.SelectedIndex = _selectedIndex;
characterName.Text = _powerAccent.CharacterDescriptions[index]; characterName.Text = _powerAccent.CharacterDescriptions[_selectedIndex];
} }
private void PowerAccent_OnChangeDisplay(bool isActive, string[] chars) private void PowerAccent_OnChangeDisplay(bool isActive, string[] chars)
@ -67,7 +64,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
if (isActive) if (isActive)
{ {
characters.ItemsSource = chars; characters.ItemsSource = chars;
characters.SelectedIndex = 0; characters.SelectedIndex = _selectedIndex;
this.UpdateLayout(); // Required for filling the actual width/height before positioning. this.UpdateLayout(); // Required for filling the actual width/height before positioning.
SetWindowPosition(); SetWindowPosition();
SetWindowAlignment(); SetWindowAlignment();