简体   繁体   中英

Can a static property of a static class be a DataMember of a BindingSource?

I have static class that has a bunch of static properties. When I try to bind the property to a BindingSource (in the UI), I can pick the static class as the DataSource, however, when I drop down the DataMember combo, there is nothing there.

Can I use a static property of a static class as a DataMember of a BindingSource?

I should mention that this is a Winforms project.

No. Most data-binding uses System.ComponentModel / TypeDescriptor , which is intrinsically instance based. You could , however, shim the static properties through a dummy object if you really wanted.

Note that additional care should be taken re thread-safety of static properties, which may make them even less desirable for direct data-binding. (or better: the use of mutable static properties should be heavily limited)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM