* 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#5762Fixes#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 a72765d705.
* Convert to target type in TemplateBinding.
* Short-circuit target type conversion for same types.
* Make sure to clean up VisualChildren and created text runs when the TextLayout is invalidate
* Remove localized comment
---------
Co-authored-by: Tim <47110241+timunie@users.noreply.github.com>
They implicitly create a new `MediaContext` via the following stacktrack, which can break subsequent tests:
```
Avalonia.Media.MediaContext..ctor(Dispatcher dispatcher) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Media\MediaContext.cs:line 44
at Avalonia.Media.MediaContext.get_Instance() in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Media\MediaContext.cs:line 68
at Avalonia.Layout.LayoutManager.QueueLayoutPass() in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Layout\LayoutManager.cs:line 356
at Avalonia.Layout.LayoutManager.InvalidateMeasure(Layoutable control) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Layout\LayoutManager.cs:line 73
at Avalonia.Layout.Layoutable.AncestorBecameVisible(ILayoutManager layoutManager) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Layout\Layoutable.cs:line 837
at Avalonia.Layout.Layoutable.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Layout\Layoutable.cs:line 803
at Avalonia.Input.InputElement.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Input\InputElement.cs:line 661
at Avalonia.Controls.Control.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Controls\Control.cs:line 533
at Avalonia.AvaloniaObject.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\AvaloniaObject.cs:line 649
at Avalonia.Animation.Animatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Animation\Animatable.cs:line 191
at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\AvaloniaObject.cs:line 700
at Avalonia.PropertyStore.EffectiveValue`1.SetAndRaiseCore(ValueStore owner, StyledProperty`1 property, T value, BindingPriority priority, Boolean isOverriddenCurrentValue, Boolean isCoercedDefaultValue) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\PropertyStore\EffectiveValue`1.cs:line 235
at Avalonia.PropertyStore.EffectiveValue`1.SetLocalValueAndRaise(ValueStore owner, StyledProperty`1 property, T value) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\PropertyStore\EffectiveValue`1.cs:line 74
at Avalonia.PropertyStore.ValueStore.SetLocalValue[T](StyledProperty`1 property, T value) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\PropertyStore\ValueStore.cs:line 220
at Avalonia.PropertyStore.ValueStore.SetValue[T](StyledProperty`1 property, T value, BindingPriority priority) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\PropertyStore\ValueStore.cs:line 196
at Avalonia.AvaloniaObject.SetValue[T](StyledProperty`1 property, T value, BindingPriority priority) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\AvaloniaObject.cs:line 336
at Avalonia.Visual.set_IsVisible(Boolean value) in D:\projects\AvaloniaUI\Avalonia\src\Avalonia.Base\Visual.cs:line 233
```
* add IsEffectivelyVisible test
* test IEV update
* update self and descendants
* sync from parent's isvisible and own on attach/detach
* update test
* update from review
* add comments
* remove whitespace changes
* Added some more IsEffectivelyVisible tests.
One failing.
* Rework UpdateIsEffectivelyVisible.
- Pass the parent state to `UpdateIsEffectivelyVisible`
- Remove some unneeded methods
- Update `IsEffectivelyVisible` before calling visual tree attach/detach events.
---------
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
* Add StartWithClassicDesktopLifetime overload with a lifetime builder
* Disallow changing Application.ApplicationLifetime after setup was completed
* Avoid static dependency on a singleton lifetime
* Introduce SetupWithClassicDesktopLifetime method
* Move more logic from Start method to Setup
* Add docs
* Avoid public API changes
* Fix tests
* Repalce locator usage with `.UseLifetimeOverride`
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Add an item with null values to the SelectingItemsControl test data
* Fixed NullReferenceException when SelectedValueBinding evulates to null
Fixed SelectedValue bindings being overwritten when a new item is selected
* Adds the ImmutablePenWithDynamicBrush and fixes Border and Shape border re-rendering when changing Brush value
* Removes the ImmutablePenWithDynamicBrush, rollback to Pen
* Cache and reuse Pen
* Move all Pen's updating logic to Pen.TryModifyOrCreate
* Add some tests for Pen.TryModifyOrCreate
* Add proper handling for DashStyle
* Invert condition in Pen.TryModifyOrCreate, fixes the logic
---------
Co-authored-by: Max Katz <maxkatz6@outlook.com>
Co-authored-by: Tim <47110241+timunie@users.noreply.github.com>
* Add SelectingItemsControl property init order tests
* Property order in SelectedItemsControl doesn't matter on init
* Fix SelectedItemsControl properties during init when Selection is set
* Fixed SelectedItemsControl.AnchorIndex after init
* TabItem.TabStripPlacemenet should be correctly set
* fix: TabItem.TabStripPlacemenet should be correctly set
* move TabItemStripPlacement assignment to PrepareContainerForItemOverride
* remove excessive UpdateTabStripPlacement call on TabStripPlacementProperty.Changed
* Updated RenderDataRectangleNode.HitTest to properly hit-test rounded rectangles.
* Moved rounded rectangle contains logic to the RoundedRect struct, added unit tests, and refactored previous RenderDataRectangleNode changes.
* Fixed a comment typo.
* Added a private access modifier to a method.
* Add failing test for RangeBase overriding Value on DataContext changed
* Add bool flag to skip coercing min, max and value while DataContext is
changing
* Add failing unit test for scenario 1 in #11878.
* Set TabOnceActiveElement on realized container.
Fixes scenario 1 in #11878.
* Use TabOnceActiveElement to decide focused element.
Fixes scenario #3 in #11878.
* Added failing unit tests for #11666.
* Handle items replaced with its own logic.
Don't rely on a remove/insert - it creates more work than needed.
* Fix some off-by-N errors in RealizedStackElements.
Fixes#11666
* Don't alter state in properties.
The `IValueEntry.HasValue` and `ValueFrame.IsActive` properties could alter state, which meant that when inspecting objects with these properties in a debugger, the state got altered by observing it. Make them methods.
* Deleted unused file.
* Add failing test for #12381.
* Use the index from the event in EvaluateIsActive.
Break the rules in this case.
Fixes#12381
---------
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* Failing unit test for #13474
* Fix for #13474 by reverting changes to ListBoxItem from #12883
* Version 2 of fix, only marks event handled for Mouse input.
* Version 3. Re-raise the event, but backup the source before doing so and restore it after. Closest in functionality to original, but preserves "correct" event source in order to allow Tapped events.
---------
Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com>
* Add failing test for #8638.
* Don't hide tooltip when pointer is over tooltip.
Fixes#8638
* Close the tooltip when pointer exits.
If the pointer has been moved from the control to the tooltip, then out of the tooltip to another control, ensure that the tooltip is closed.
* AdornedControl can be a standard CLR property.
* Add diagnostics support to the Avalonia.Build.Tasks
* HostApp and generators build fix
* Diagnostics support in Avalonia XAML
* Support multiple style selector errors at once
* Improve avalonia intrinsics error handling + add tests
* Add CompiledBindings multiple errors tests
* Fix name generator
* Make AvaloniaXamlIlDuplicateSettersChecker a warning
* Fix Style_Parser_Throws_For_Duplicate_Setter test
* Make XamlLoaderUnreachable respect warnings settings
* Add AvaloniaXamlIlStyleValidatorTransformer
* Throw more specific exceptions instead of XamlParseException
* Get rid of XamlXDiagnosticCode to simplify diagnostics code
* Simplify XAML exceptions by avoiding DiagnosticCode in them
* Simplify XamlCompilerDiagnosticsFilter
* Don't use AvaloniaXamlDiagnosticCodes in Avalonia.Generators
* Fix some error handlings in compiler task
* Update editor config for in-solution analysis
* Update XamlX
* Fix missing document path
* Avoid Description field usage
* Add AvaloniaXamlVerboseExceptions property and make exception formatting customizable
* Make Avalonia.NameGenerator not crash if there are XAML errors, members should still be generated
* Update tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleIncludeTests.cs
---------
Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com>
* Test - On empty PM/AM designator on culture info the time picker should show AM/PM
* On empty PM/AM designator on culture info the time picker should show AM/PM
* Remove focus hack from Popup.
* Added failing focus scope tests.
* Refactor focus scopes in FocusManager.
- Store focused element within a scope using an attached property (like WPF)
- Store current focus root so that focus can be restored to that root when a focused control or active focus scope is removed
Fixes#13325
* Suppress API compat error.
This was being produced for a compiler-generated enumerable class that was erroneously being included in the reference assembly for `FocusManager`.
* Remove focus hack from ContextMenu.
And add failing test now that the hack is removed.
* Try to return a rooted host visual.
Fixes failing test from previous comment where focus wasn't restored when closing a context menu.
* Introduce ErrorConverter and DisplayErrors attached properties
- the converter can be used to change the way a message is print
- we use DisplayErrors to get the converted error messages
* Adjust FluentTheme
* [WIP] Add a sample Page for DataValidationErrors
* use a private attached property to store recent errors
this approach gets rid of the need to DisplayErrors property
* Update samples with some additional details
* Reuse rich SetError logic in DataGrid as well
* Unify some code with OnErrorsOrConverterChanged
* Restore old behavior with null default value
* Add SetErrorConverter test
---------
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* Try to find nearest matching glyphTypeface when no exact match could by found by SystemFontCollection
* Fix glyphTypeface caching
* Rework SystemFontCollection TryCreateGlyphTypeface
* Make sure a failed glyphTypeface lookup is cached
* Make sure to only try to get nearest match if we failed to load the font via font magager impl
* Apply font simulations if possible
* Enable font simulation for embedded fonts
* Adjust simulated angle