dotnet / dotnet/wpf

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

Open
#10,746 4 comments 0 reactions 0 assignees View on GitHub
API suggestion
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### 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

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

### API Usage

```xaml

```

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.