Skip to content

[API Proposal]: Fallback when binding target type does not match #10746

Open
@Laniusexcubitor

Description

@Laniusexcubitor

Background and motivation

Currently when we use a binding with an interface we get a binding error or warning when the source type does not implement the interface: TargetException:'System.Reflection.TargetException: Object does not match target type.
Sometimes this is completely ok, but we get a nasty binding warning in XAML Binding failures when a FallBack value has been set otherwise a binding error is generated.
I propose a new property on a binding like FallbackOnUnmatchedTargetType that will suppress the resulting binding warning.

API Proposal

public class Binding : BindingBase
{
    // ...
    [DefaultValue(false)]
    public bool FallbackOnUnmatchedTargetType { get; set }
}

API Usage

<TextBox Text="{Binding Path=(namespace:IInterface.SomeProperty), FallbackOnUnmatchedTargetType=True, FallBackValue={x:Null}}" />

Alternative Designs

No response

Risks

This would not change the current behavior except of suppressing the current warning/error. Using the property developers are saying that they know that there will be unmatched objects, and they don't need a warning about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API suggestionEarly API idea and discussion, it is NOT ready for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions