From c2d5f623900051910d105d661715479b9ca6d5e3 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 20 Jan 2020 11:01:35 +0100 Subject: [PATCH] Avoid boxing if property is correct type. For typed bindings, we'll have an `AvaloniaPropertyChangedEventArgs` where `T` is the same as the type of the `AvaloniaPropertyObservable`. For non-typed bindings we'll have `object` as `T` so use the non-typed `AvaloniaProperty`. --- .../Reactive/AvaloniaPropertyObservable.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs b/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs index 100330ed1d..238aba5c96 100644 --- a/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs +++ b/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs @@ -44,7 +44,16 @@ namespace Avalonia.Reactive { if (e.Property == _property) { - var newValue = e.Sender.GetValue(e.Property); + T newValue; + + if (e is AvaloniaPropertyChangedEventArgs typed) + { + newValue = typed.Sender.GetValue(typed.Property); + } + else + { + newValue = (T)e.Sender.GetValue(e.Property); + } if (!Equals(newValue, _value)) {