質問編集履歴
1
INotifyPropertyChangedを実装している基底クラスを載せました。IDataErrorInfoも載っていますが、気にしないでください。
test
CHANGED
File without changes
|
test
CHANGED
@@ -174,6 +174,100 @@
|
|
174
174
|
|
175
175
|
|
176
176
|
|
177
|
+
基底クラスでINotifyPropertyChangedを実装しています。
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
using System.Collections.Generic;
|
182
|
+
|
183
|
+
using System.ComponentModel;
|
184
|
+
|
185
|
+
using System.Runtime.CompilerServices;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
namespace Utility
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
public abstract class BaseData
|
194
|
+
|
195
|
+
: System.ComponentModel.IDataErrorInfo
|
196
|
+
|
197
|
+
, System.ComponentModel.INotifyPropertyChanged
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
protected BaseData()
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
_errors = new Dictionary<string, string>();
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
#region IDataErrorInfo Interface
|
212
|
+
|
213
|
+
protected Dictionary<string,string> _errors;
|
214
|
+
|
215
|
+
protected bool HasError { get { return _errors.Count != 0; } }
|
216
|
+
|
217
|
+
protected void AddError( string Message, [CallerMemberName] string propertyName = "" )
|
218
|
+
|
219
|
+
{
|
220
|
+
|
221
|
+
_errors [propertyName] = Message;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
protected void RemoveError( [CallerMemberName] string propertyName = "" )
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
_errors.Remove( propertyName );
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
public virtual string Error { get { return null; } }
|
234
|
+
|
235
|
+
public string this [string name]
|
236
|
+
|
237
|
+
{
|
238
|
+
|
239
|
+
get { return _errors.ContainsKey( name ) ? _errors [name] : null; }
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
#endregion
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
#region INotifyPropetyChanged
|
248
|
+
|
249
|
+
public event PropertyChangedEventHandler PropertyChanged;
|
250
|
+
|
251
|
+
public void NotifyEvent( [CallerMemberName] string propertyName = "" )
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
PropertyChanged?.Invoke( this, new PropertyChangedEventArgs( propertyName ) );
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
#endregion
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
177
271
|
###試したこと
|
178
272
|
|
179
273
|
更新タイミングをOnPropertyChangedに変えると、2つのプロパティにfalseが入ってきました。
|