Steven Kirk 3b1eb338e6 Binding System refactor (#13970)
* Update ncrunch config.

* WIP: Benchmarks

* Initial refactor of binding infrastructure.

- `ExpressionObserver` has been removed and its functionality merged with `BindingExpression`
- `BindingExpression` handles all types of `BindingMode` itself; doesn't require `BindingOperations.Apply` to set up a separate observable for `TwoWay/`OneWayToSource` bindings
  - This allows us to fix some long-standing issues with `OneWayToSource` bindings
- Expression nodes have been refactored
  - No longer split between `Avalonia.Base` and `Avalonia.Markup`
  - Categorize them according to whether they use reflection or not

A few tests are failing around binding warnings: this is because the next step here is to fix binding warnings.

* Make default binding Source = UnsetProperty.

Null is a theoretically valid value for `Source`; setting it to null shouldn't mean "use the data context".

* Move logging to BindingExpression.

As `BindingExpression` now has enough information to decide when it's appropriate to log an error/warning or not.

Fixes #5762
Fixes #9422

* Add compatibility hack for older compiled bindings.

Previously, `CompiledBindingPathBuilder` didn't have a `TemplatedParent` method and instead the XAML compiler rewrite templated parent bindings to be a `$self.TemplateParent` property binding. resulting in extraneous logs.

Add a constructor with an  `apiVersion`  to `CompiledBindingPathBuilder` which will be used by newer versions of the XAML compiler, and if a usage is detected using an `apiVersion` of 0, then upgrade `$self.TemplatedParent` to use a `TemplatedParentPathElement`.

* Log errors from property accessors.

* Don't log errors for named control bindings...

...on elements which aren't yet rooted.

* Log errors for failed conversions.

* Use consistent wording for binding warnings.

"Could not convert" instead of "Cannot convert".

* Log warnings for converter exceptions.

* Don't convert new TargetTypeConverters each time.

* Added failing test for implicit conversion.

* Support cast operators in compiled bindings.

A bit of a hack as we'd ideally not be using reflection when using compiled bindings.

* This shouldn't be a public API.

Should only be used for tests.

* Make enum/int conversion work.

* Check for SetValue equality after conversion.

And also use "identity equals" where value types and strings use `object.Equals` and reference types use `object.ReferenceEquals`.

* Added ConverterCulture back to bindings.

* Fix merge error.

Removed deleted files from csproj that were re-added due to indentation changes.

* Use BindingExpression directly in ValueStoe.

* Introduce BindingExpressionBase.

And `UntypedBindingExpressionBase`.

* Make TemplateBinding a BindingExpression.

* Make DynamicResource use a BindingExpression.

* WIP: Start exposing a BindingExpression API.

* Finish exposing a BindingExpression API.

* Fix OneTimeBinding.

* Remove unneeded classes/methods.

* Don't call obsolete API.

* Make BindingExpressionBase the public API.

This matches WPF's API.

* Added BindingExpressionBase.UpdateTarget.

* Initial implementation of UpdateSourceTrigger.

* Don't use weak references for values.

If they're boxed values, they can get collected.

* No need for virtual/generic methods here now.

* Reintroduce support for binding anchors.

Turns out these were needed by animations, just our animation system has no unit tests so I missed that fact earlier. Add a basic animation unit test that fails without anchor support, and add binding anchors back in. Currently a private API as I suspect this feature shouldn't be needed outside the framework.

* Include new property in clone.

And add real-life example of `UpdateSourceTrigger=LostFocus` to BindingDemo.

* Fix merge error.

* Updated BindingExpression tests.

- Make them run for both compiled and reflection bindings (found a bunch of tests that fail with compiled bindings)
- Make them not depend on converting the `BindingExpression` to an observable and instead test the end result of the binding on an `AvaloniaObject`

* Fix compiled binding indexer tests.

* Use data validation plugins in PropertyAccessorNode.

Added a warning suppression for now: we may need a separate `DataValidators` list for AOT-friendly plugins.

* Don't separate plugins by reflection.

`DataAnnotationsValidationPlugin` is public and so it can't be moved. No point in moving the others if this one will be in the wrong place.

* Remove unneeded methods.

* Make reflection binding tests use a string.

Convert the `System.Linq.Expression` to a string and then use this, as reflection bindings will always be instanced with a string path.

* Added TODO12 plan for IBinding2.

* Use more specific exception.

* Fix nits from code review.

* Make expression nodes sealed where possible.

* Unsubscribe on Stop, don't re-subscribe.

D'oh.

* Tweak ExpressionNode lists.

Saves a few K in benchmarks and it's a cleaner API.

* Add a pooled option in BindingExpressionGrammar.

Micro-optimization.

* Avoid allocations when enumerating binding plugins.

* Add IBinding2 support to observable bind overloads.

In the case of `TemplateBinding`, the `IObservable<object?>` bind overload is selected by C#. Add an explicit check for an `IBinding2` here to use the more performant code-path.

* Remove disposed binding from ImmediateBindingFrame.

* Added TemplateBinding benchmarks.

* Remove duplicate items.

Seems to have been caused by a merge error.

* Fix exception when closing color picker.

And add tests.

* Don't skip converter when binding to self.

* Don't pass UnsetValue to converters.

This follows WPF behavior.

* Log element name if present.

More useful than just logging the control hash code.

* Respect binding priority.

* Throw on mismatched binding priorities.

We don't want to respect the binding priority in this case as it breaks `TemplateBindings` when the default `LocalValue` priority is passed. Instead make sure that the priority parameter matches that of the expression.

This reverts commit a72765d70514506d94b39ba33a3d91e11cd6dcd4.

* Convert to target type in TemplateBinding.

* Short-circuit target type conversion for same types.
2024-01-29 08:08:26 +00:00
2024-01-29 08:08:26 +00:00
2023-07-05 15:37:50 -04:00
2024-01-28 22:27:25 +03:00
2024-01-29 08:08:26 +00:00
2020-05-11 20:51:10 -03:00
2024-01-29 08:08:26 +00:00
2024-01-29 08:08:26 +00:00
2013-12-05 21:16:06 +01:00
2020-11-02 11:45:11 +01:00
2022-10-05 16:01:29 +02:00
2022-10-05 16:01:29 +02:00
2022-10-05 16:01:29 +02:00
2020-04-01 01:02:28 +03:00
2023-04-19 19:58:34 -07:00
2021-02-08 20:29:15 +00:00
2023-01-08 00:17:53 -05:00
2024-01-10 13:29:30 -08:00
2014-12-04 19:55:49 +01:00

Star our repo to show support Header

Telegram Gitter Discord Build Status Backers on Open Collective Sponsors on Open Collective GitHub Sponsors License
NuGet downloads Size

📖 About

Avalonia is a cross-platform UI framework for dotnet, providing a flexible styling system and supporting a wide range of platforms such as Windows, macOS, Linux, iOS, Android and WebAssembly. Avalonia is mature and production ready and is used by companies, including Schneider Electric, Unity, JetBrains and GitHub.

Considered by many to be the spiritual successor to WPF, Avalonia UI provides a familiar, modern development experience for XAML developers creating cross-platform applications. While Avalonia UI is similar to WPF, it isn't a 1:1 copy, and you'll find plenty of improvements.

For those seeking a cross-platform WPF, we have created Avalonia XPF, enabling WPF applications to run on macOS and Linux with little to no code changes. Avalonia XPF is a commercial product and is licensed per-app, per-platform.

Blog

To see the latest announcements and read about the state of Avalonia, check out the Avalonia UI Blog.

Breaking Changes

You can also see what breaking changes we have planned and what our past breaking changes have been.

Awesome Avalonia

Awesome Avalonia is community-curated list of awesome Avalonia UI tools, libraries, projects and resources. Go and see what people are building with Avalonia!

🚀 Getting Started

See our Get Started guide to begin developing apps with Avalonia UI.

Visual Studio

The Avalonia Visual Studio Extension contains project and control templates that will help you get started, or you can use the .NET Core CLI. For a starter guide see our documentation.

JetBrains Rider

JetBrains Rider now has official support for Avalonia.

Code completion, inspections and refactorings are supported out of the box, for XAML previewer add https://plugins.jetbrains.com/plugins/dev/14839 to plugin repositories and install AvaloniaRider plugin.

Avalonia Packages

Avalonia is delivered via NuGet package manager. You can find the packages here: https://www.nuget.org/packages/Avalonia/

Use these commands in the Package Manager console to install Avalonia manually:

Install-Package Avalonia
Install-Package Avalonia.Desktop

Showcase

Showcase_Banner

See what others have built with Avalonia UI on our Showcase. We welcome submissions!

Bleeding Edge Builds

We also have a nightly build which tracks the current state of master. Although these packages are less stable than the release on NuGet.org, you'll get all the latest features and bugfixes right away and many of our users actually prefer this feed!

Learning

Documentation

Documentation can be found at https://docs.avaloniaui.net.

Tutorials

We also have a tutorial over there for newcomers.

Samples

We have a range of samples to help you get started.

Building and Using

See the build instructions here.

Contributing

This project exists thanks to all the people who contribute.

Please read the contribution guidelines before submitting a pull request.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.

Licence

Avalonia is licenced under the MIT licence.

Donate

Donating to the project is a fantastic way to thank our valued contributors for their hard work. Your donations are shared among our community and awarded for significant contributions.

If you need support see Commercial Support section below.

Donate with BTC or use Open Collective.

BTC: bc1q05wx78qemgy9x6ytl5ljk2xrt00yqargyjm8gx

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Commercial Support

We have a range of support plans available for those looking to partner with the creators of Avalonia, enabling access to the best support at every step of the development process.

Please note that donations are not considered payment for commercial support agreements. Please contact us to discuss your needs first. team@avaloniaui.net

.NET Foundation

This project is supported by the .NET Foundation.

Avalonia XPF

Unleash the full potential of your existing WPF apps with our cross-platform UI framework, enabling WPF apps to run on macOS and Linux without requiring expensive and risky rewrites.

GH_Banner

S
Description
No description provided
Readme 144 MiB
Languages
C# 97.9%
Objective-C++ 1.3%
TypeScript 0.5%
Objective-C 0.1%