teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

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

2016/08/20 12:41

投稿

Tak1wa
Tak1wa

スコア4791

answer CHANGED
@@ -9,8 +9,11 @@
9
9
  xmlns:local="clr-namespace:WpfApplication2"
10
10
  mc:Ignorable="d"
11
11
  Title="MainWindow" Height="350" Width="525">
12
+ <Window.DataContext>
13
+ <local:MainWindowViewModel />
14
+ </Window.DataContext>
12
15
  <Grid>
13
- <local:UserControl1 prop="1" />
16
+ <local:UserControl1 prop="{Binding num}" />
14
17
  </Grid>
15
18
  </Window>
16
19
  ```
@@ -49,21 +52,26 @@
49
52
  }
50
53
  ```
51
54
  ```C#
52
- public class MainWindowViewModel : INotifyPropertyChanged
55
+ public class MainWindowViewModel : INotifyPropertyChanged
53
- {
56
+ {
54
- private int _num;
57
+ private int _num;
55
- public int num
58
+ public int num
56
- {
59
+ {
57
- get
60
+ get
58
- {
61
+ {
59
- return _num;
62
+ return _num;
60
- }
63
+ }
61
- set
64
+ set
62
- {
65
+ {
63
- _num = value;
66
+ _num = value;
64
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("num"));
67
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("num"));
65
- }
68
+ }
66
- }
69
+ }
67
- public event PropertyChangedEventHandler PropertyChanged;
70
+ public event PropertyChangedEventHandler PropertyChanged;
71
+
72
+ public MainWindowViewModel()
73
+ {
74
+ num = 10;
68
- }
75
+ }
76
+ }
69
77
  ```