回答編集履歴
1
バインドできてなかったので訂正
test
CHANGED
@@ -20,9 +20,15 @@
|
|
20
20
|
|
21
21
|
Title="MainWindow" Height="350" Width="525">
|
22
22
|
|
23
|
+
<Window.DataContext>
|
24
|
+
|
25
|
+
<local:MainWindowViewModel />
|
26
|
+
|
27
|
+
</Window.DataContext>
|
28
|
+
|
23
29
|
<Grid>
|
24
30
|
|
25
|
-
<local:UserControl1 prop="
|
31
|
+
<local:UserControl1 prop="{Binding num}" />
|
26
32
|
|
27
33
|
</Grid>
|
28
34
|
|
@@ -100,38 +106,48 @@
|
|
100
106
|
|
101
107
|
```C#
|
102
108
|
|
103
|
-
|
109
|
+
public class MainWindowViewModel : INotifyPropertyChanged
|
104
110
|
|
105
|
-
|
111
|
+
{
|
106
112
|
|
107
|
-
|
113
|
+
private int _num;
|
108
114
|
|
109
|
-
|
115
|
+
public int num
|
110
116
|
|
111
|
-
|
117
|
+
{
|
112
118
|
|
113
|
-
|
119
|
+
get
|
114
120
|
|
115
|
-
|
121
|
+
{
|
116
122
|
|
117
|
-
|
123
|
+
return _num;
|
118
124
|
|
119
|
-
|
125
|
+
}
|
120
126
|
|
121
|
-
|
127
|
+
set
|
122
128
|
|
123
|
-
|
129
|
+
{
|
124
130
|
|
125
|
-
|
131
|
+
_num = value;
|
126
132
|
|
127
|
-
|
133
|
+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("num"));
|
128
134
|
|
129
|
-
|
135
|
+
}
|
130
136
|
|
131
|
-
|
137
|
+
}
|
132
138
|
|
133
|
-
|
139
|
+
public event PropertyChangedEventHandler PropertyChanged;
|
134
140
|
|
141
|
+
|
142
|
+
|
143
|
+
public MainWindowViewModel()
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
num = 10;
|
148
|
+
|
135
|
-
}
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
136
152
|
|
137
153
|
```
|