winforms
winforms copied to clipboard
DataBinding: incompatible data type conversion shows no reaction
.NET version
7.0
Did it work in .NET Framework?
No
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
If a DataBinding is created between two properties of incompatible data types, nothing happens at runtime, so it's harder to find the causing problem. I bind a property of a control to a property of a class via a BindingSource. If the data types of the properties fit, everything is fine. If they doesn't fit, the setter of the property won't be reached. But there is also no exception about the problem. Neither when not-reaching the setter nor at the app start to tell be that a DataBinding problem exists.
Steps to reproduce
Test project: WinFormsNetVB.zip
- start the app
- click the button
- the setters of both properties of the
Fooclass will be reached - stop the app
- change the code: in the class
Foo, change the type of the field_ClassBand the propertyClassBfromClassBtoClassA - start the app
- click the button
- the setter of the
ClassBproperty of theFooclass will not be reached. There is also no exception message.
I expect an exception that tells me, that the data bound properties are type-incompatible, either when setting the data binding (mostly at app start) or at least when the magic of data binding will be activated after changing one of the bound properties.
@KlausLoeffelmann might be the person to talk to about this.
"Funny" enough, there actually is a build-in infrastrucutre in WinForms, and for its days, it is not even bad. The thing is, it's a nightmare to discover.
And that's the reason, we need to consider a safe and predictable way to expose this. I say safe, because the internals purely based on reflection might not be ideal, let alone, when it comes to performance.
So, my proposal is introducing IValueConverter for WinForms, which can get honored by the BindingClass. I think, that's a reasonable thing to do.
And shouldn't be too hard.
@elachlan: BTW: It's the MVP Summit this week, so I am super busy and hard to get. But feel free to take a look what I am doing in-between, and feel also free to ping me directly, if you have ideas, concerns, questions, you might want to address quickly. Thanks for your help here!
@KlausLoeffelmann what would be the next step for this issue then? Can you point to the existing docs for the feature?
@KlausLoeffelmann do you have an issue for the proposal you cite? If not please create one and link it here. We'll then be able to close this issue as it will be resolved by the Converters proposal.
Hi @merriemcgaw and @KlausLoeffelmann! We are thinking for various options to enable our clients use the DateOnly and TimeOnly types inside our DateTimePicker control. The control is currently working with the DateTime struct. Definitely support for the IValueConverter interface inside the BindingClass could help. Will this feature make it to .NET 9?
@icom85 this feature won't make .NET 9, but if it's something that will be beneficial I can get it on the backlog for .NET 10. I can see the benefit for sure. @KlausLoeffelmann / @JeremyKuhne what do you guys think?