reactiveui / ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.

Home Page:https://www.reactiveui.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Mark ReactiveObject IObservable properties with DisplayAttribute for Winforms

Micha-kun opened this issue · comments

Describe the bug 🐞

When binding a model class into databinding controls like DevExpress ones in WinForms, because it does not implement DisplayAttribute from System.Component.DataAnnotations with Order set to -1, automatically is binding those IObservable properties from ReactiveObject and you manually need to remove them every time you bind new objects. Actually those properties are implementing two attributes: IgnoreDataMember and JsonIgnore.

Properties are:

  • Changing
  • Changed
  • ThrownExceptions

Step to reproduce

  1. Create a form and include a Grid control
  2. Bind to that control a BindingSource mapping to the class that implements ReactiveObject class
  3. Bind data to that BindingSource
  4. Start the app and see that grid control is showing by default those properties because they're not implementing DisplayAttribute

Reproduction repository

No response

Expected behavior

When those properties are fixed, by default should ignore those properties for databinding.

Screenshots 🖼️

image

IDE

Visual Studio 2022, Visual Studio 2019, Visual Studio 2017

Operating system

Windows

Version

No response

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

I don't know if other frameworks like WPF are affected with this behavior.

This is the DevExpress documentation around the use of Data Annotations attributes:

https://docs.devexpress.com/WindowsForms/18273/common-features/data-binding/data-annotation-attributes

Is there an attribute for the annotations that makes the property grid not generate for that property. Doing a quick hunt

Browsable(false) by the looks. Wouldn't that be more suitable?

Hmm... Maybe both are required (depending on the control is binded)? In DevExpress controls , at least, the one that works is [Display(Order = -1)]

image

Hmmm there are other properties on DisplayAttribute that prevents to generate the column:
[Display(Order = -1)] hides the column but [Display(AutoGenerateField = false)] prevents the column automatic generation and [Display(AutoGenerateFilter = false)] prevents the column to be used on filters.

So, the correct attribute usage should be [Browsable(false), Display(Order = -1, AutoGenerateField = false, AutoGenerateFilter = false)]

anyway open to having these attributes on the class mentioned providing it can be handled by all platforms etc.

Happy to take a PR if you like and we can get it in the next release?

BTW I suspect for other platforms like WPF it'll be a good thing. WPF doesn't come with a native property grid, but almost all I know of work like the winforms one and obey those properties. Eg I suspect the problem you're having would be a issue even with the native winforms propertygrid not just the devexpress ones.

Ok! I'm going to make a PR :)

It worked! YESSS!

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.