1
1
// Copyright (c) 2023 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
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 ;
9
4
using Microsoft . UI . Xaml . Controls ;
10
- using Microsoft . UI . Xaml . Controls . Primitives ;
11
5
12
6
namespace Files . App . UserControls . KeyboardShortcut
13
7
{
@@ -28,10 +22,24 @@ private void OnSizeChanged()
28
22
{
29
23
}
30
24
31
- private void OnHotKeysChanged ( )
25
+ private async void OnHotKeysChanged ( )
32
26
{
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
+
33
38
if ( HotKeys . IsEmpty )
39
+ {
40
+ keyboardShortcutItemsControl . ItemsSource = null ;
34
41
return ;
42
+ }
35
43
36
44
List < KeyboardShortcutItem > items = [ ] ;
37
45
@@ -94,10 +102,7 @@ void GetModifierCode(KeyModifiers modifier)
94
102
}
95
103
96
104
// Set value
97
- if ( GetTemplateChild ( KeyboardShortcutItemsControl ) is ItemsControl keyboardShortcutItemsControl )
98
- {
99
- keyboardShortcutItemsControl . ItemsSource = items ;
100
- }
105
+ keyboardShortcutItemsControl . ItemsSource = items ;
101
106
}
102
107
}
103
108
}
0 commit comments