From d01a98770864a9b113ba320119fb8ebcee2e31a4 Mon Sep 17 00:00:00 2001 From: Johannes <51154169+JoeVoo@users.noreply.github.com> Date: Wed, 19 Feb 2025 14:02:15 +0100 Subject: [PATCH 1/2] Update TypedBinding.cs Remove the null value Exception --- src/CommunityToolkit.Maui.Markup/TypedBinding.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CommunityToolkit.Maui.Markup/TypedBinding.cs b/src/CommunityToolkit.Maui.Markup/TypedBinding.cs index 264f4528..e99f573d 100644 --- a/src/CommunityToolkit.Maui.Markup/TypedBinding.cs +++ b/src/CommunityToolkit.Maui.Markup/TypedBinding.cs @@ -248,7 +248,7 @@ void ApplyCore(TSource? sourceObject, BindableObject target, BindableProperty pr var needsSetter = (mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource; if (needsSetter && sourceObject is not null) { - var value = GetTargetValue(target.GetValue(property), typeof(TProperty)) ?? throw new InvalidOperationException("Unable to find target value"); + var value = GetTargetValue(target.GetValue(property), typeof(TProperty)); if (!BindingExpressionHelper.TryConvert(ref value, property, typeof(TProperty), false)) { @@ -435,4 +435,4 @@ void Unsubscribe() handle.Listener?.Unsubscribe(); } } -} \ No newline at end of file +} From d9ccbfafb98b0adf24ca6cb12ba516c5fdffd8a2 Mon Sep 17 00:00:00 2001 From: Johannes <51154169+JoeVoo@users.noreply.github.com> Date: Sat, 22 Feb 2025 20:36:26 +0100 Subject: [PATCH 2/2] Update TypedBinding.cs newerly i got an error message on the TryConvert line with ref value is null. I managed this with the added lines. --- src/CommunityToolkit.Maui.Markup/TypedBinding.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/CommunityToolkit.Maui.Markup/TypedBinding.cs b/src/CommunityToolkit.Maui.Markup/TypedBinding.cs index e99f573d..dd99d6c8 100644 --- a/src/CommunityToolkit.Maui.Markup/TypedBinding.cs +++ b/src/CommunityToolkit.Maui.Markup/TypedBinding.cs @@ -249,7 +249,12 @@ void ApplyCore(TSource? sourceObject, BindableObject target, BindableProperty pr if (needsSetter && sourceObject is not null) { var value = GetTargetValue(target.GetValue(property), typeof(TProperty)); - + if (value == null) + { + setter?.Invoke(sourceObject,default!); + return; + } + if (!BindingExpressionHelper.TryConvert(ref value, property, typeof(TProperty), false)) { BindingDiagnostics.SendBindingFailure(this, sourceObject, target, property, "Binding", BindingExpression.CannotConvertTypeErrorMessage, value, typeof(TProperty));