-
-
Notifications
You must be signed in to change notification settings - Fork 78
Update to Avalonia v11.3.9 and Implement ResourceDictionary DSL #483
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
base: master
Are you sure you want to change the base?
Update to Avalonia v11.3.9 and Implement ResourceDictionary DSL #483
Conversation
* Extend subscription system from Control to AvaloniaObject for broader compatibility * Improve code formatting and documentation with XML comments Breaking Changes: - Avalonia.FuncUI.Types.Subscription.Subscribe now accepts AvaloniaObject instead of Control
* Support both Uri and string-based factory methods (fromUri, fromString) Technical Details: - ResourceInclude doesn't inherit AvaloniaObject, solved with wrapper pattern - ResourceInclude cannot update internal state, handled by instance recreation - Added Headless test infrastructure for proper UI thread execution
…ructure - Add StyledElement.resources IView overload for DSL-style resource management - Create TestHelpers.fs with reusable Headless, VirtualDom, and Assert modules - Reorganize tests by functionality with improved module structure
…nt subscriptions and ResourceProvider
Migrated from manual session management with custom code using only Avalonia.Headless to framework-managed approach with Avalonia.Headless.XUnit, resolving "Call from invalid thread" errors and test hanging issues. - Add Avalonia.Headless.XUnit package reference - Change UI thread accessing tests to use [AvaloniaFact] attribute - Remove unnecessary manual session management code Note: Avalonia.Headless was initially introduced in commit 3c67231 to implement tests containing XAML code.
|
@SilkyFowl wow, nice work! Would be interesting to see how / what you use this for in your apps. Mainly for defining theme resources in F# I assume? |
|
@JaggerJo Thank you for the review! Yes, the primary use case is defining theme resources in F# without XAML. I plan to add a sample project to the Long-term VisionLong-term, I want to achieve DSL-ification of the App class. To accomplish this, I recognize that we need to solve the #86 issue. Challenges and Potential Solutions
I'll create a separate issue to discuss these long-term goals in more detail. |
|
Sounds interesting, I'll have a look at the changes tommorow |
- Add ColorPicker DSL - Add themeVariantScopeView
…features - Refactor ColorSet to use SolidColorBrush directly - Replace GetResourceObservable().ToBinding() with DynamicResourceExtension - Add debugOverlaysView for renderer diagnostics (DEBUG only) - Simplify .editorconfig and fix formatting across DSL files - Restrict DiagnosticsSupport package to DEBUG builds only
…mponent development - Add FuncCommand helper for ICommand implementation (DEBUG only) - Change MainWindow from HostWindow to Window with self-reference (as this) - Add F12 key binding to open InspectorWindow - Add Avalonia.FuncUI.Diagnostics project reference (DEBUG only) - Prevent multiple inspector windows from opening
This PR updates Avalonia from v11.1.0 to v11.3.9. With this version update,
ResourceDictionarynow inherits fromAvaloniaObject, enabling us to implement ResourceDictionary-related DSL bindings.Changes
Avalonia Version Update
ResourceDictionary DSL Implementation
New file: ResourceDictionary.fs
ResourceDictionary.keyValue: Supports setting key-value pairsobj) and IView valuesClearValuetypeResourceDictionary.mergedDictionaries: Supports merged dictionariesResourceDictionary.themeDictionariesKeyValue: Supports theme variant-specific resource dictionariesResourceInclude Wrapper Implementation
Since
ResourceIncludedoes not inherit fromAvaloniaObject, we implemented aResourceIncludeWrapperclass:ResourceIncludewith a class that inherits fromResourceProviderSourceproperty changes to ensure resource updatesfromUri,fromStringResourceProvider DSL Implementation
New file: ResourceProvider.fs
onResourceObservable: Binding that subscribes toGetResourceObservabledefaultThemeVariantparameteroptiontype (treatingnullandUnsetValueasNone)StyledElement DSL Extensions
StyledElement.fs
StyledElement.resources: Added overload that acceptsIViewStyledElement.onResourceObservable: Resource observation binding for StyledElementTest Infrastructure Improvements
Avalonia.Headless.XUnitpackage: Required for testingResourceIncludeTestHelpers.fs: Assertion helpers for testsStyledElementTests.fsTestResources1.xaml,TestResources2.xamlMinor Fixes
AttrBuilder.fs: Fixed typos in documentation commentsTypes.fs,VirtualDom.Delta.fs,VirtualDom.Patcher.fs: Fixed typos in documentation commentsImplementation Details and Future Improvements
Dictionary-Type Property Implementation
Dictionary-type properties such as
ResourceDictionary.keyValueandthemeDictionariesKeyValueare currently implemented usingAttrBuilder<'t>.CreateContentSingle. While this approach is unconventional, it has the beneficial side effect of allowing Views and raw values to be seamlessly mixed.Current Implementation (Works)
Potential Future Improvement
If we were to provide a more explicit and type-safe API, it might look like this:
Usage example with this API:
However, this change would require a significant update to the DSL API. If we decide to pursue this approach, it should be handled in a separate issue and pull request.