* Reminder for future me.
* Move compiled bindings to Avalonia base.
* Update suppressions.
* Tweaked `BindingExpressionVisitor`.
And documented public (internal) API.
* Fix ncrunch config.
* Add comprehensive unit tests for BindingExpressionVisitor.
Tests cover all supported features including property access, indexers,
AvaloniaProperty access, logical NOT, stream bindings, and type operators.
Also includes tests for unsupported operations that should throw exceptions.
Discovered bug: IsAssignableFrom check at line 139 is backwards, causing
upcasts to incorrectly throw and downcasts to be incorrectly ignored.
Bug is documented with skipped tests showing expected behavior and passing
tests documenting current broken behavior.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Fix backwards IsAssignableFrom check in BindingExpressionVisitor.
Fixed the inheritance cast check which was inverted, causing:
- Upcasts (derived→base) to incorrectly throw exceptions
- Downcasts (base→derived) to be incorrectly ignored
Changed line 139 from:
node.Operand.Type.IsAssignableFrom(node.Type)
to:
node.Type.IsAssignableFrom(node.Operand.Type)
This correctly identifies safe upcasts (which are ignored) vs unsafe
downcasts (which throw exceptions).
Updated tests to remove skip attributes and removed the temporary tests
that documented the broken behavior. All 33 tests now pass.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Allow downcasts and all reference type casts in binding expressions.
Changed the cast handling to allow both upcasts and downcasts for reference
types. This makes casts actually useful in binding expressions while still
rejecting value type conversions that would require actual conversion logic.
The logic now checks:
- Both types must be reference types (not value types)
- One type must be assignable to/from the other (either direction)
This allows practical scenarios like:
- Upcasts: (BaseClass)derived
- Downcasts: (DerivedClass)baseInstance
- Casting through object: (TargetType)(object)source
The binding system will gracefully handle any runtime type mismatches.
Updated tests to verify downcasts are allowed and added test for casting
through object pattern.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Add clarifying test for cast transparency in binding expressions.
Added test showing that casts are transparent in property chains.
For example, ((TestClass)x).Property produces just one node for the
property access - the cast doesn't create additional nodes.
This clarifies that empty nodes for (TestClass)x is correct behavior:
- Empty nodes = bind to source directly
- The cast is just a type annotation, transparent to the binding path
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Fix: Casts should create ReflectionTypeCastNode, not be transparent.
Casts were incorrectly being treated as transparent (not creating nodes),
but CompiledBindingPath uses TypeCastPathElement which creates FuncTransformNode.
For consistency and correctness, BindingExpressionVisitor should also create
cast nodes using ReflectionTypeCastNode.
Changes:
- Convert expressions now create ReflectionTypeCastNode
- TypeAs expressions now create ReflectionTypeCastNode
- Both upcasts and downcasts create nodes (runtime checks handle failures)
Examples:
- x => (TestClass)x → 1 node (cast)
- x => ((TestClass)x).Prop → 2 nodes (cast + property)
- x => x.Child as object → 2 nodes (property + cast)
This matches the behavior of CompiledBindingPathBuilder.TypeCast<T>().
Updated all related tests to verify cast nodes are created.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Use compiled cast functions instead of reflection-based type checks.
Changed from ReflectionTypeCastNode (which uses Type.IsInstanceOfType) to
FuncTransformNode with a compiled cast function. This matches how
CompiledBindingPath handles TypeCastPathElement and provides better
performance by avoiding reflection.
The CreateCastFunc method compiles an expression `(object? obj) => obj as T`
which generates efficient IL similar to the 'is T' pattern used in
TypeCastPathElement<T>, rather than using reflection-based type checks.
Performance improvement:
- Before: Type.IsInstanceOfType() reflection call for each cast
- After: Compiled IL using 'as' operator (same as TypeCastPathElement<T>)
Updated tests to expect FuncTransformNode instead of ReflectionTypeCastNode.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Reuse TypeCastPathElement<T> cast function directly.
Instead of compiling our own cast expression, extract the Cast delegate
directly from TypeCastPathElement<T>. This ensures we use the exact same
code path as CompiledBindingPath, avoiding any potential behavioral
differences and code duplication.
Benefits:
- Code reuse - single implementation of cast logic
- Consistency - same behavior as CompiledBindingPathBuilder.TypeCast<T>()
- No duplicate expression compilation logic
Implementation uses reflection to create the closed generic type and
extract the pre-compiled Cast delegate, which is still more efficient
than reflection-based type checks at runtime.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Revert to lambda compilation approach for cast functions.
Reverted from using TypeCastPathElement<T> back to compiling lambda
expressions directly. The lambda approach is cleaner and more straightforward:
Benefits of lambda compilation:
- No Activator.CreateInstance call (avoids reflection for construction)
- More direct - creates exactly what we need
- No coupling to TypeCastPathElement internal implementation
- Simpler code flow
The compiled lambda generates the same efficient IL code (using 'as' operator)
as TypeCastPathElement<T> does, just without the indirection.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Code cleanup: Fix XML docs and remove unused usings.
- Changed CreateCastFunc XML docs to use <remarks> tag for better formatting
- Removed unused 'using Avalonia.Data;' from tests
- Removed redundant '#nullable enable' from tests
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Refactor BindingExpressionVisitor to use CompiledBindingPathBuilder.
Changes BindingExpressionVisitor to use CompiledBindingPathBuilder instead of
directly creating ExpressionNode instances, unifying the approach with
compile-time XAML bindings. Adds new BuildPath() method that returns
CompiledBindingPath, while maintaining backwards compatibility through the
existing BuildNodes() wrapper method.
Key changes:
- Replace internal List<ExpressionNode> with CompiledBindingPathBuilder
- Refactor all visitor methods to call builder methods
- Add accessor factory methods and implementations for property access
- Support AvaloniaProperty, CLR properties, arrays, indexers, streams, casts
- Update tests to expect PropertyAccessorNode, StreamNode, ArrayIndexerNode
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Remove CompiledBindingPathFromExpressionBuilder in favor of BindingExpressionVisitor.
Now that BindingExpressionVisitor has been refactored to use
CompiledBindingPathBuilder and provides a BuildPath() method, the test-only
CompiledBindingPathFromExpressionBuilder class is redundant and can be removed.
Changes:
- Replace CompiledBindingPathFromExpressionBuilder.Build() with
BindingExpressionVisitor<TIn>.BuildPath() in BindingExpressionTests
- Delete CompiledBindingPathFromExpressionBuilder.cs test file
- All 122 tests in BindingExpressionTests.Compiled continue to pass
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Move test-only methods from production code to test extensions.
Removes BindingExpression.Create and BindingExpressionVisitor.BuildNodes
from production code since they were only used by unit tests.
Changes:
- Remove BindingExpression.Create<TIn, TOut> method
- Remove BindingExpressionVisitor.BuildNodes method
- Add BindingExpressionVisitorExtensions in Base.UnitTests
- Add BindingExpressionExtensions in LeakTests
- Add static helper methods in test classes to reduce noise
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Add public CompiledBinding.Create factory methods from LINQ expressions.
Adds two static factory methods to create CompiledBinding instances from
lambda expressions using BindingExpressionVisitor.BuildPath():
- Create<TIn, TOut>(expression, converter, mode)
Creates binding without explicit source (uses DataContext)
- Create<TIn, TOut>(source, expression, converter, mode)
Creates binding with explicit source
This provides a type-safe, ergonomic API for creating compiled bindings
from code without string-based paths.
Usage:
var binding = CompiledBinding.Create(viewModel, vm => vm.Title);
textBlock.Bind(TextBlock.TextProperty, binding);
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Merge CompiledBinding.Create overloads and add all binding property parameters.
Consolidates the two Create method overloads into a single method with source
as an optional parameter. Adds optional parameters for all CompiledBinding
properties (priority, converterCulture, converterParameter, fallbackValue,
stringFormat, targetNullValue, updateSourceTrigger, delay) per PR feedback.
Properties that default to AvaloniaProperty.UnsetValue (source, fallbackValue,
targetNullValue) use null-coalescing to convert null parameter values.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* (Re-)update suppressions.
* Add missing using.
* Fix ncrunch build.
* Remove file I committed by accident.
* PR feedback.
* Store static members outside generic class.
Based on PR feedback.
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
* On Frame-Buffer-Orientation: Add screen orientation support for Linux frame buffer and DRM applications.
This commit introduces support for screen orientation across various components by adding a new `Orientation` property of type `SurfaceOrientation` in `DrmOutputOptions` and `FbDevOutputOptions`. The `IScreenInfoProvider` interface is updated to inherit from `ISurfaceOrientation`, ensuring consistent orientation management.
Key changes include:
- Enhanced `FramebufferToplevelImpl` to handle orientation in size calculations.
- Updated `LibInputBackend` for device input coordinate rotation based on screen orientation.
- Implemented `ISurfaceOrientation` in `DrmOutput` and `FbdevOutput` classes.
- Modified `DrawingContextImpl` to support canvas rotation based on orientation.
- Improved `FramebufferRenderTarget` and `PixelFormatConversionShim` to respect framebuffer orientation during surface creation and pixel format conversions.
- Streamlined rendering methods to ensure drawing operations align with the current surface orientation.
- Removed redundant code related to framebuffer handling.
* Fix review comments, add ability to test
* Some formatting
* Should be working now
* Remove fbdev changes
Theres really no point to do this in fbdev.
* Better method of rotating and transforming the canvas
* Remove breaking changes
* Switch to using a 2nd frame buffer in the rotation case
* Fix review comments
* Incorrect variable
* Fix sample
---------
Co-authored-by: davidw <davidw@icselectronics.co.uk>
* Remove the flowDirection parameter from TextCollapsingProperties.CreateCollapsedRuns
* Simplify text formatting constructors
* Update API suppressions
* #19962 Add AXAML Source Information to debug Builds
* SimplifyXamlSourceInfo
* Add XamlSourceInfo for as many elements as possible
* Add tests to confirm XamlSourceInfo is set for all types
* Remove property only added for debugging during development
* update skipped test so it runs (even though it doesn't yet pass)
* Wrap XamlAstNewClrObjectNode instead of XamlAstObjectNode, run transformer late
* Remove unsupported value types from the More_Resources_Get_XamlSourceInfo_Set
* Fix Document property not being set in runtime parser
* Add a dedicated CreateSourceInfo parameter for RuntimeXamlLoaderConfiguration, instead of reusing DesignMode
* Inherit real XamlValueWithManipulationNode, move actual manipulation to a separate class
* Fix group transformers by unwrapping manipulation nodes first
* minor Resource related test change
* Update public API as agreed
* Add new failing tests for the dictionaries
* Fix randomly failing tests, that depend on the test order
* Fix assert
* Rename AvaloniaXamlResourceTransformer
* Emit XamlSourceInfo from AvaloniaXamlResourceTransformer
* Rename AvaloniaXamlIlResourceTransformer for consistency
* Cleanup comments
* Remove XamlSourceInfoValueWithManipulationNode, use standard XamlValueWithManipulationNode
* Add new RuntimeXamlLoaderDocument.Document property
* Use UriBuilder trick to support unix paths on windows
* Add private AttachedProperty for avalonia objects, instead of always using weak table
* Fix wrong UriBuilder usage and add more test assets
* Fix "Invalid URI" exception
---------
Co-authored-by: KimHenrik <kimhenrik@outlook.de>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* Implemented LiveSetting property
* Make sure PropertyChanged callback is called on AvnAutomationPeer
* Remove `optional` from `AvnAccessibility`: we were never checking whether they respond to the selector or not anyway
* Formatting
* Use ARIA and Live Region Changed constants from mac APIs
* Fixed Mac build
* Reverted constants that don't exist on integration test XCode version
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* feat: disable scroll chaining for AutoCompleteBox, ComboBox, and MenuScrollViewer.
* feat: disable scroll chaining for AutoCompleteBox, ComboBox, and MenuFlyoutPresenter
* feat: enable scroll chaining for ScrollViewer in MenuFlyoutPresenter.
* Introduce TextOptions API
* Store BaselinePixelAlignment as byte. Move to a dedicated file.
* Update API suppressions
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Reduce the number of WrapDirect3D11Texture calls
Reduce the number of WrapDirect3D11Texture calls by tying the EglSurface lifetime to _renderTexture.
When testing on a 4K display, I observed that eglCreatePbufferFromClientBuffer, which is invoked by WrapDirect3D11Texture, can take around 5 ms per frame.
By reducing the number of eglCreatePbufferFromClientBuffer calls, I was able to improve rendering performance by about 30%.
However, I’m not sure why the previous implementation needed to call WrapDirect3D11Texture on every frame.
* Remove the commented code
* Added `ExpanderAutomationPeer` for `Expander` control
* Use Group/"group" on UIA and NSAccessibilityDisclosureTriangleRole on AX
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>