Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/CommunityToolkit.Maui.Markup/TypedBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,13 @@ 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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should check whether TProperty is nullable in this scenario. Thoughts @TheCodeTraveler?

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));
Expand Down Expand Up @@ -435,4 +440,4 @@ void Unsubscribe()
handle.Listener?.Unsubscribe();
}
}
}
}