質問編集履歴
2
text1の小文字を大文字に変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,8 +24,8 @@
|
|
24
24
|
<StackPanel Orientation="Vertical">
|
25
25
|
<!-- TextBox x:Name="Text1" />
|
26
26
|
<TextBox x:Name="Text2" / -->
|
27
|
-
<TextBox x:Name="Text1" Text="{Binding
|
27
|
+
<TextBox x:Name="Text1" Text="{Binding Text1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
|
28
|
-
<TextBox x:Name="Text2" Text="{Binding
|
28
|
+
<TextBox x:Name="Text2" Text="{Binding Text2,Mode=TwoWay,UpdateSourceTrigger=Explicit}"/>
|
29
29
|
</StackPanel>
|
30
30
|
</Grid>
|
31
31
|
</Window>
|
1
DataContextを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -43,6 +43,7 @@
|
|
43
43
|
public MainWindow()
|
44
44
|
{
|
45
45
|
InitializeComponent();
|
46
|
+
DataContext = new MyViewModel();
|
46
47
|
|
47
48
|
Text1.Text = "test1";
|
48
49
|
Text2.Text = "test2";
|
@@ -52,6 +53,45 @@
|
|
52
53
|
be.UpdateSource();
|
53
54
|
be = Text2.GetBindingExpression(TextBox.TextProperty);
|
54
55
|
be.UpdateSource();
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
// DataContext
|
60
|
+
public class MyViewModel : INotifyPropertyChanged
|
61
|
+
{
|
62
|
+
private string _text1;
|
63
|
+
public string Text1
|
64
|
+
{
|
65
|
+
get { return _text1; }
|
66
|
+
set
|
67
|
+
{
|
68
|
+
if (_text1 != value)
|
69
|
+
{
|
70
|
+
_text1 = value;
|
71
|
+
OnPropertyChanged("Text1");
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
private string _text2;
|
77
|
+
public string Text2
|
78
|
+
{
|
79
|
+
get { return _text2; }
|
80
|
+
set
|
81
|
+
{
|
82
|
+
if (_text2 != value)
|
83
|
+
{
|
84
|
+
_text2 = value;
|
85
|
+
OnPropertyChanged("Text2");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
public event PropertyChangedEventHandler PropertyChanged;
|
91
|
+
|
92
|
+
protected void OnPropertyChanged(string propertyName)
|
93
|
+
{
|
94
|
+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
55
95
|
}
|
56
96
|
}
|
57
97
|
}
|