Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

DingpingZhang/DataBinding

Repository files navigation

The library was used as an experimental demo and is no longer maintained.

The functionality has been migrated to WpfExtensions.Binding, or get it from version.


DataBinding

What is it

Automatically subscribe and unsubscribe all of INotifyPropertyChanged objects in the expression you provided. It can analyze conditional expressions and raise the PropertyChanged event when appropriate.

How to use

  • Common
// ExpressionObserver.Observes<T>(Expression<Func<T>, Action<T, Exception>): void
ExpressionObserver.Observes(
    () => a.BoolProp ? a.NestedProp.StringProp : a.StringProp,
    (value, exception) =>
    {
        // On value changed
    });
  • Computed Property (like vue.js)
public class ViewModel : BindableBaseEx
{
    public double RectangularArea => GetProperty(() => Width * Height);
}

How it works

Any expression will be parsed into a dependency graph and a conditional expression tree.

  • Dependency Graph: Each dependency node corresponds to an property (or closure field) in the expression you provoded. When an INPC property changed, its corresponding dependency node will unsubscribe from the old INPC object and subscribe to the new INPC object, and notify its downstream nodes to unsubscribe and subscribe.
  • Conditional Expression Tree: Control the activation state of dependency nodes, and an inactivated dependency node will not observe the PropertyChanged event. Maybe it can improve performance.
  • See 考不上三本也会实现数据绑定(三) for details.

Some dependency graph examples

dependency-graph

dependency-graph

dependency-graph

dependency-graph

dependency-graph

License

Anti-996 License-1.0

About

Implement a simple one-way data binding feature with C#.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages