[英]Is there a way to implement similar Raise Property Changed for VS2015?
Seems I have syntax errors in VS2015 for the code below.似乎我在 VS2015 中有以下代码的语法错误。 The error sounds like:
错误听起来像:
A value of type '?'
'?' 类型的值cannot be used as a default parameter because there are no standard conversions to type 'T'
不能用作默认参数,因为没有到类型“T”的标准转换
Is there a way to implement similar "Raise property changed" in VS2015?有没有办法在 VS2015 中实现类似的“Raise property changed”?
public class ViewModel : ViewModelBase
{
// Property
public const string SelectedItemPropertyName = "SelectedItem";
private int? _selectedItem;
public int? SelectedItem
{
get
{
return _selectedItem;
}
set
{
Set(SelectedItemPropertyName, ref _selectedItem, value);
}
}
// Method
private void Load()
{
int number = SelectedItem ?? -1;
// do your work
}
// Raise property changed
public override void RaisePropertyChanged<T>([CallerMemberName] string propertyName = null, T oldValue = default, T newValue = default, bool broadcast = false)
{
base.RaisePropertyChanged(propertyName, oldValue, newValue, broadcast);
if (propertyName == nameof(SelectedItem))
Load();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.