我有一个属性,RaisePropertyChanged(PropName, oldValue, true, true)
当我不再有任何与互联网的连接时,它会抛出我在错误线程上的异常。所以我想从我的 ViewModel 更新属性,但是如何在我的 ViewModel 中获取当前线程,或者你对解决方案有什么建议?
我的 ViewModel-ctor
public MyViewModel()
{
// START LISTENING TO NETWORKSTATUS
NetworkInformation.NetworkStatusChanged += OnNetworkStatusChangedHandler;
}
NetworkChanged-回调方法
private async void OnNetworkStatusChangedHandler(object sender)
{
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null)
{
IsRefreshEnabled = false;
}
else
{
IsRefreshEnabled = true;
}
}
我的财产
public const string IsRefreshEnabledPropertyName = "IsRefreshEnabled";
private bool _isRefreshEnabled = true;
public bool IsRefreshEnabled
{
get { return _isRefreshEnabled; }
set
{
if (_isRefreshEnabled == value) { return; }
var oldValue = _isRefreshEnabled;
_isRefreshEnabled = value;
RaisePropertyChanged(IsRefreshEnabledPropertyName, oldValue, value, true);
}
}
提前致谢!