回答編集履歴

1

バインドできてなかったので訂正

2016/08/20 12:41

投稿

Tak1wa
Tak1wa

スコア4791

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="1" />
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
- public class MainWindowViewModel : INotifyPropertyChanged
109
+ public class MainWindowViewModel : INotifyPropertyChanged
104
110
 
105
- {
111
+ {
106
112
 
107
- private int _num;
113
+ private int _num;
108
114
 
109
- public int num
115
+ public int num
110
116
 
111
- {
117
+ {
112
118
 
113
- get
119
+ get
114
120
 
115
- {
121
+ {
116
122
 
117
- return _num;
123
+ return _num;
118
124
 
119
- }
125
+ }
120
126
 
121
- set
127
+ set
122
128
 
123
- {
129
+ {
124
130
 
125
- _num = value;
131
+ _num = value;
126
132
 
127
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("num"));
133
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("num"));
128
134
 
129
- }
135
+ }
130
136
 
131
- }
137
+ }
132
138
 
133
- public event PropertyChangedEventHandler PropertyChanged;
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
  ```