質問編集履歴

3

add

2016/03/02 07:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -52,8 +52,8 @@
52
52
 
53
53
 
54
54
 
55
- これって、Buttonを押した瞬間にrectangleのFocusはbuttonに移ってしましょうか?
55
+ これって、Buttonを押した瞬間にrectangleのFocusはbuttonに移っているようです。
56
56
 
57
57
 
58
58
 
59
- もしってしまうなら、移る前のfocused objectを取得したいです。
59
+ 移る前のfocused objectを取得したいです。

2

修正

2016/03/02 07:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  Title="MainWindow" Height="350" Width="525">
16
16
 
17
- <StackPanel Name="panel">
17
+ <StackPanel Name="panel" FocusManager.IsFocusScope="True">
18
18
 
19
19
  <Rectangle Name="rectangle1" Focusable="True" Fill="#FFF4F4F5" Height="100" Stroke="Black" MouseUp="Rectangle_MouseUp"/>
20
20
 
@@ -34,11 +34,15 @@
34
34
 
35
35
  private void Button_Click(object sender, RoutedEventArgs e) {
36
36
 
37
- //focusしたオブジェクトを取得したい。
37
+ //focusしたオブジェクトを取得したい。
38
38
 
39
- Rectangle rectangle = this.ActiveControl;//C# Formなら。
39
+ //Rectangle rectangle = this.ActiveControl;//C# Formなら。
40
40
 
41
41
  //rectangle = FocusManager.GetFocusedElement as Rectangle;//動かない。
42
+
43
+ IInputElement focusedElement = FocusManager.GetFocusedElement(panel);
44
+
45
+ Rectangle rectangle = (Rectangle)focusedElement;
42
46
 
43
47
 
44
48
 

1

誤字

2016/03/02 07:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -38,6 +38,10 @@
38
38
 
39
39
  Rectangle rectangle = this.ActiveControl;//C# Formなら。
40
40
 
41
+ //rectangle = FocusManager.GetFocusedElement as Rectangle;//動かない。
42
+
43
+
44
+
41
45
  }
42
46
 
43
47
  ```