Properly attach / detach events when the characteristic is changed

This commit is contained in:
Arlo Godfrey 2022-09-26 12:13:52 -05:00 коммит произвёл Michael Hawker MSFT (XAML Llama)
Родитель c9895b218b
Коммит cadc08b9b3
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -134,8 +134,6 @@ namespace Microsoft.Toolkit.Uwp.Connectivity
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
ReadValueAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
characteristic.ValueChanged += Characteristic_ValueChanged;
}
/// <summary>
@ -152,6 +150,16 @@ namespace Microsoft.Toolkit.Uwp.Connectivity
{
if (_characteristic != value)
{
if (value is not null)
{
value.ValueChanged += Characteristic_ValueChanged;
}
if (_characteristic is not null)
{
_characteristic.ValueChanged -= Characteristic_ValueChanged;
}
_characteristic = value;
OnPropertyChanged();
}