-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] General purpose data binding support? #15140
Comments
FYI, XAML implementation has been discussed in #14862. |
Would useful especially when creating multimedia apps or games. |
I think this needs more detail. Its currently too abstract.
[edit] |
The interface is similar to here: Okay; this is a working (but rough prototype) example: I have renamed Binding Mecanism
Example Custom Framework
Example "UI" Control
Example Application
Example Application Output
I am not sure what you mean here; the
I believe that a simple binding mechanism like this would be useful in a general sense; absolutely. As I said in my first post, a XAML-like template parser would be quite nice for some use-cases; but in the case of an platform like Unity it would be nice if the XAML control generation could be custom implemented; i.e. just using the XML as a template with bindings whereby the output is platform-specific. In the above example there is no I hope that this helps to elaborate on my request :) [Edit: Finished implementing |
I am not familiar with the WPF/Silverlight DependencyProperties; but looking at the following page of the MSDN documentation I don't see why a https://msdn.microsoft.com/en-gb/library/cc903933(v=vs.95).aspx |
Since the foundation of your design is that properties are observable, I think you should formalize that into an
I think Now [edit]
|
I considered (and even prototyped) using wrapper properties like this; but I thought that it was quite a bit messier to add validation to the view model because of the need to plumb delegates into the wrapper. Also note that it is not necessary to implement the The I believe that the |
It is also possible to define specialized For example, at the moment Unity UI doesn't implement the
Which can then be used in the view like follows:
The view still has the ability to automatically nuke the bindings when its cleanup time. |
The main issue I see is that you need to guarantee an observable property. Currently, there is no way to do that. Adding an |
The solution needs to follow C#'s "strongly typed" nature. A binding should fail at compile time, not runtime. If it fails at runtime then its more "dynamic typed". |
If a class doesn't implement If a class does implement As far as I can tell; the https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx In fact; this approach is suggested in the Prism project by Microsoft Practices: Excerpt:
For instance, a lot of developers are applying patterns like MVVM using the Edit: Having a separate I apologise if I have misunderstood your comments. |
hmm, I wonder; Roslyn is quite powerful... perhaps there is a way to create one of those new "code analyzers" to detect non-existent properties ahead of time and present a non-blocking warning?.. just a thought I would experiment with that; but I haven't figured out how to make those yet. |
I think its important to get this right if you want to make it part of CoreFX (force it on others). INotifyPropertyChanged is very fragile. It would also be preferable to get away from |
As I was prototyping an adaptor for INotifyPropertyChanged, I noticed it has another design defect: since its an interface, there is no guarantee that the object notifying you of a change is the object that actually has the property you are interested in.
|
As noted above, since its an interface, you can not make that assertion. A class can be observable with a different class providing INotifyPropertyChanged.
It also means that is not conclusive. |
Hmm, in what scenario might another class want to implement I will spend some more time experimenting with the property wrapper approach; I already have a prototype of that implemented. |
The only concern is that the design allows for it. |
It should be noted that a) Yes you could make a Roslyn analyzer to catch mistakes in string property names but also
|
@SamuelEnglard Excellent point; thanks! |
@kruncher You're welcome. I do like the idea of having a binding framework independent of a UI framework. Another thought though would be to have weak bindings as well as string ones, so that bindings don't have to keep objects alive |
Absolutely; the introduction of a For platforms that support JIT it's also possible to create some extension methods on the binding manager for extra syntax sugar by using expressions to determine the source/target object and the property name:
But, of course, in order to support platforms that are constrained to AOT it is still necessary to use the more traditional approach with the likes of strings and the awesome new |
I had considered
This still does not correct the design defect in |
Dependence upon a I don't really see anything wrong with using reflection here. I think that it's way more important that such a binding system supports all the hundreds of thousands of classes that have already been implemented using this mechanism. The objective of the binding mechanism is to bind the properties of two objects without those two objects needing to know about the binding mechanism. By following this standardized approach it is easily possible to reuse all existing view models with Microsoft/Xamarin XAML; with this general purpose binding mechanism and with Windows Forms data binding. There is nothing to prevent you from being able to use this same mechanism with the property-wrapper approach if that is what you prefer; since you could just implement a custom
|
Existing code wont be using these proposed non-standard binding interfaces (i.e. ObservableProperty's and ObservableAttribute's); so I don't see how it would break since it wouldn't actually work in the first place... If developers use |
One of the use-cases I envision (and why I am pursuing an implementation of this) is in animation. Its common to "bind" a timeline to class properties. This means the code will be called at least 60 times (or more) a second by multiple callers. This constraint implies the code needs to be highly performant, not produce garbage, and avoid boxing/unboxing. It also needs to be highly durable without assumptions at runtime. The current INotify design is none of these things. |
It is straightforward to avoid the garbage produced when raising the You can avoid boxing/unboxing of values inside the binding for JIT-enabled platforms since you can build a delegate which operates on the value types instead. |
The intent was that
This will have no impact on binding TO a property. To bind FROM a property, this functionality is already required.
What exactly does "BindOnce" do behavior wise? If something is only ever bound once, why is a binding necessary? Wouldn't it be more efficient and intuitive to just specify |
I would have to see an example use of that to understand what is meant. Requiring methods to be dynamically constructed at runtime is a rather obtuse work-around. As I understand it, currently you have to use reflection to get the property and then call a method to set its value. The method that does that ( |
You have to modify existing application code to add the attribute.
It executes the binding one time; yes you can just manually assign the value if you prefer; but this does have uses when automatically generating bindings:
Not to forget the fact that the binding mechanism applies This is a typical mode of operation for binding:
Many reflection-based operations can be optimized by having .NET emit the code at runtime which improves performance and can help to avoid boxing: I believe that Linq utilizes a lot of expression trees. |
So to get the syntax sugar with an expression tree: http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression
|
A thought to solve the reflection speed issue: Reflection Emit? |
there are dreams of wanna be scientists and there are engineering tasks of practicioners. I say - give us WPF-style binding with inotifyproperychanged now. we (people who makes actual software) need it yesterday. you can still build parallel strong typed binding separately and see how many people will use it.. |
haven't followed the discussion, but maybe this code of mine is useful: |
I'm also interested in this feature. Any updates on this? Are there maybe any open source libraries that we could use for this? |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
I see above "ericstj modified the milestones: 5.0.0, Future on Jul 2, 2020" Has anyone followed this and should it indeed be removed from backlog? |
Given the lack of interest, I don't think we're gonna invest in this any time soon. And if we did, I would most likely be driven by a client framework team (WinForms/WPF, MAUI etc) |
Like that though it will eventually end up having similar functionality in different variations at various UI frameworks (even though the functionality is not just for UIs). However designing it in a way that ti will cover all such frameworks' needs (including future ones) would need quite some research I guess. |
It depends; we've gotten much better of collaborating across different teams in the platform layer (mostly thanks to OSS). |
BTW, apart from UI Frameworks, one should maybe also take in mind Data Flow frameworks (say Workflow Foundation) |
We do have various tools for that:
They aren't like Workflow Foundation which would allow persisting/resuming, but they are supportive of modelling data flows in concurrent systems. It depends on the needs. FWIW, Workflow Foundation is a legacy technology at this point. I don't believe there is any appetite in bringing this to .NET Core. |
Please forgive me if this is the wrong place to post this; but it certainly seems like a good place :)
I think that it would be extremely useful if there were a general-purpose data binding mechanism providing a consistent way to synchronize the properties of objects making it for developers to have consistent support for patterns that benefit from data binding such as the popular MVVM and MVPVM design patterns.
Also including the
IValueConverter
interface and related functionality that is included in theSystem.Windows.Data
namespace of the fully featured .NET framework but perhaps in a less platform-specific namespace likeSystem.Data
?Whilst not applicable in the following example; perhaps a general purpose XAML implementation would also be of benefit perhaps allowing a XAML representation of a custom selection of UI controls outside the scope of Windows or Xamarin forms? I see this being of particular use in .NET Core based game engines.
Example Use Case (User Code)
For example, if the Unity game engine was using .NET Core with such a feature it would then be quite straightforward to add binding support to the Unity UI controls simply by having them implement
INotifyPropertyChanged
.Programmatic Bindings
Continuing with the Unity example; some
MonoView<TViewModel>
-derived component could be added to the root of each composition of UI controls allowing for manual binding similar to this:Where the base classes look like this:
Designer Specified Bindings
In addition to programmatic binding (like above) it would also be fairly straightforward to create a custom "PropertyBinder"
MonoBehaviour
component which could be added to UI controls to allow designers to make similar associations using just the Unity "Inspector" window.Bindings properly disposed when removed/cleared from the
Bindings
collectionWhen the view is unbound from the data context all
Bindings
would be properly disposed allowing the view to be reused and bound to another view model.Closing Words
I'm sure that you folks have probably already got something like this planned; but I wanted to post this feature request just in case it isn't on the roadmap :)
The text was updated successfully, but these errors were encountered: