11// Copyright (c) 2023 Files Community
22// Licensed under the MIT License. See the LICENSE.
33
4- using CommunityToolkit . WinUI . UI ;
5- using Microsoft . UI . Input ;
6- using Microsoft . UI . Xaml ;
7- using Microsoft . UI . Xaml . Automation ;
8- using Microsoft . UI . Xaml . Automation . Peers ;
94using Microsoft . UI . Xaml . Controls ;
10- using Microsoft . UI . Xaml . Controls . Primitives ;
115
126namespace Files . App . UserControls . KeyboardShortcut
137{
@@ -28,10 +22,24 @@ private void OnSizeChanged()
2822 {
2923 }
3024
31- private void OnHotKeysChanged ( )
25+ private async void OnHotKeysChanged ( )
3226 {
27+ var keyboardShortcutItemsControl = GetTemplateChild ( KeyboardShortcutItemsControl ) as ItemsControl ;
28+ for ( int i = 0 ; i < 100 && keyboardShortcutItemsControl is null ; i ++ )
29+ {
30+ // Wait for KeyboardShortcutItemsControl to be loaded
31+ await Task . Delay ( 10 ) ;
32+ keyboardShortcutItemsControl = GetTemplateChild ( KeyboardShortcutItemsControl ) as ItemsControl ;
33+ }
34+
35+ if ( keyboardShortcutItemsControl is null )
36+ return ;
37+
3338 if ( HotKeys . IsEmpty )
39+ {
40+ keyboardShortcutItemsControl . ItemsSource = null ;
3441 return ;
42+ }
3543
3644 List < KeyboardShortcutItem > items = [ ] ;
3745
@@ -94,10 +102,7 @@ void GetModifierCode(KeyModifiers modifier)
94102 }
95103
96104 // Set value
97- if ( GetTemplateChild ( KeyboardShortcutItemsControl ) is ItemsControl keyboardShortcutItemsControl )
98- {
99- keyboardShortcutItemsControl . ItemsSource = items ;
100- }
105+ keyboardShortcutItemsControl . ItemsSource = items ;
101106 }
102107 }
103108}
0 commit comments