回答編集履歴
4
initialを追加
test
CHANGED
@@ -104,7 +104,7 @@
|
|
104
104
|
|
105
105
|
{
|
106
106
|
|
107
|
-
public HogeVM TextBoxX { get; set; } = new HogeVM();
|
107
|
+
public HogeVM TextBoxX { get; set; } = new HogeVM(initial: 2);
|
108
108
|
|
109
109
|
}
|
110
110
|
|
@@ -118,9 +118,15 @@
|
|
118
118
|
|
119
119
|
|
120
120
|
|
121
|
-
private double x
|
121
|
+
private double x ;
|
122
|
+
|
122
|
-
|
123
|
+
public HogeVM(double initial)
|
124
|
+
|
123
|
-
|
125
|
+
{
|
126
|
+
|
127
|
+
x = initial;
|
128
|
+
|
129
|
+
}
|
124
130
|
|
125
131
|
public string Text
|
126
132
|
|
3
例の追加
test
CHANGED
@@ -85,3 +85,133 @@
|
|
85
85
|
|
86
86
|
|
87
87
|
とバインドしてはどうでしょうか。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
---
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
こんな感じです。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```C#
|
102
|
+
|
103
|
+
class MainVM : ViewModel
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
public HogeVM TextBoxX { get; set; } = new HogeVM();
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
class HogeVM : ViewModel
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
private double x = 2;
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
public string Text
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
get
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
return this.x.ToString();
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
set
|
140
|
+
|
141
|
+
{
|
142
|
+
|
143
|
+
Console.WriteLine("set");
|
144
|
+
|
145
|
+
if (this.Text == value)
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
return;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
double v;
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
try
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
v = double.Parse(value);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
catch
|
168
|
+
|
169
|
+
{
|
170
|
+
|
171
|
+
this.RaisePropertyChanged(() => this.Text);
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
return;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
this.x = v;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
this.RaisePropertyChanged(() => this.Text);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```xml
|
198
|
+
|
199
|
+
<Window ...
|
200
|
+
|
201
|
+
>
|
202
|
+
|
203
|
+
<Window.DataContext>
|
204
|
+
|
205
|
+
<local:MainVM/>
|
206
|
+
|
207
|
+
</Window.DataContext>
|
208
|
+
|
209
|
+
<StackPanel>
|
210
|
+
|
211
|
+
<TextBox Text = "{Binding TextBoxX.Text}"/>
|
212
|
+
|
213
|
+
</StackPanel>
|
214
|
+
|
215
|
+
</Window>
|
216
|
+
|
217
|
+
```
|
2
修正
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
```C#
|
2
2
|
|
3
3
|
public class HogeVM : ... //いい名前が思いつかなかった
|
4
|
+
|
5
|
+
// 何かしら継承する
|
4
6
|
|
5
7
|
{
|
6
8
|
|
@@ -11,6 +13,10 @@
|
|
11
13
|
*/
|
12
14
|
|
13
15
|
private double x;
|
16
|
+
|
17
|
+
public HogeVM(double initial){/*省略*/}
|
18
|
+
|
19
|
+
|
14
20
|
|
15
21
|
public string Text
|
16
22
|
|
@@ -58,9 +64,9 @@
|
|
58
64
|
|
59
65
|
```C#
|
60
66
|
|
61
|
-
public HogeVM XTextBox {get;} = new HogeVM(initial
|
67
|
+
public HogeVM XTextBox {get;} = new HogeVM(initial : 0);
|
62
68
|
|
63
|
-
public HogeVM YTextBox {get;} = new HogeVM(initial
|
69
|
+
public HogeVM YTextBox {get;} = new HogeVM(initial : 0);
|
64
70
|
|
65
71
|
```
|
66
72
|
|
1
コメント受けて修正
test
CHANGED
File without changes
|