回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,95 +1,48 @@
|
|
1
|
-
```x
|
1
|
+
```xml
|
2
|
-
|
3
2
|
<TextBox Text="{Binding Contents, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
4
|
-
|
5
3
|
```
|
6
|
-
|
7
4
|
これで十分なら話は早いです。これだけで機能します。
|
8
|
-
|
9
|
-
|
10
5
|
|
11
6
|
---
|
12
7
|
|
13
|
-
|
14
|
-
|
15
8
|
`PropertyChanged`にできない(したくない)場合は、タブの切り替え時に`TextBox`の`LostFocus`が呼ばれないようなので、無理やり呼ぶような感じでしょうか。
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
```
|
10
|
+
```cs
|
20
|
-
|
21
11
|
using System.Collections.ObjectModel;
|
22
|
-
|
23
12
|
using System.ComponentModel;
|
24
|
-
|
25
13
|
using System.Windows;
|
26
|
-
|
27
14
|
using System.Windows.Controls;
|
28
|
-
|
29
15
|
using System.Windows.Input;
|
30
16
|
|
31
|
-
|
32
|
-
|
33
17
|
namespace Questions279056
|
34
|
-
|
35
18
|
{
|
36
|
-
|
37
19
|
public partial class MainWindow : Window
|
38
|
-
|
39
20
|
{
|
40
|
-
|
41
21
|
public ObservableCollection<TabItem> Tabs { get; set; } = new ObservableCollection<TabItem>();
|
42
|
-
|
43
22
|
public MainWindow()
|
44
|
-
|
45
23
|
{
|
46
|
-
|
47
24
|
InitializeComponent();
|
48
|
-
|
49
25
|
DataContext = Tabs;
|
50
|
-
|
51
26
|
Tabs.Add(new TabItem { Header = "Tab1", Contents = "aaa" });
|
52
|
-
|
53
27
|
Tabs.Add(new TabItem { Header = "Tab2", Contents = "bbb" });
|
54
|
-
|
55
28
|
Tabs.Add(new TabItem { Header = "Tab3", Contents = "ccc" });
|
56
29
|
|
57
|
-
|
58
|
-
|
59
30
|
Tab.IsSynchronizedWithCurrentItem = true;
|
60
|
-
|
61
31
|
Tab.Items.CurrentChanging += Items_CurrentChanging;
|
62
|
-
|
63
32
|
}
|
64
33
|
|
65
|
-
|
66
|
-
|
67
34
|
private void Items_CurrentChanging(object sender, CurrentChangingEventArgs e)
|
68
|
-
|
69
35
|
{
|
70
|
-
|
71
36
|
if(Keyboard.FocusedElement is TextBox textBox)
|
72
|
-
|
73
37
|
textBox.RaiseEvent(new RoutedEventArgs(LostFocusEvent));
|
74
|
-
|
75
38
|
}
|
76
|
-
|
77
39
|
}
|
78
40
|
|
79
|
-
|
80
|
-
|
81
41
|
public class TabItem
|
82
|
-
|
83
42
|
{
|
84
|
-
|
85
43
|
public string Header { get; set; }
|
86
|
-
|
87
44
|
public string Contents { get; set; }
|
88
|
-
|
89
45
|
}
|
90
|
-
|
91
46
|
}
|
92
|
-
|
93
47
|
```
|
94
|
-
|
95
48
|
(もうちょっとましな方法がある気がする^^;
|