回答編集履歴
1
試したコード
test
CHANGED
@@ -1,3 +1,37 @@
|
|
1
1
|
CanvasはFocusableプロパティのデフォルトがfalseになっているようなので、trueにしてください。
|
2
2
|
|
3
3
|
あとはフォーカスが当たっていればキーイベントが来るはずです。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```xaml
|
8
|
+
|
9
|
+
<Window x:Class="WpfApplication1.MainWindow"
|
10
|
+
|
11
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
12
|
+
|
13
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
14
|
+
|
15
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
16
|
+
|
17
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
18
|
+
|
19
|
+
xmlns:local="clr-namespace:WpfApplication1"
|
20
|
+
|
21
|
+
mc:Ignorable="d"
|
22
|
+
|
23
|
+
Title="MainWindow" Height="350" Width="525"
|
24
|
+
|
25
|
+
FocusManager.FocusedElement="{Binding ElementName=aa}"
|
26
|
+
|
27
|
+
>
|
28
|
+
|
29
|
+
<Canvas PreviewKeyDown="Canvas_PreviewKeyDown" x:Name="aa" Focusable="True">
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
</Canvas>
|
34
|
+
|
35
|
+
</Window>
|
36
|
+
|
37
|
+
```
|