-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add TreeViewItemIndentConverter for dynamic margin calculation #18718
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
Conversation
You can test this PR using the following package version. |
|
@cla-avalonia agree |
API diff for review: +namespace Avalonia.Controls.Converters
+{
+ public class TreeViewItemIndentConverter : IMultiValueConverter
+ {
+ public static readonly TreeViewItemIndentConverter Instance;
+ public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture);
+ }
+} |
This can be internal. |
Notes from the API review: We spent quite a bit of time debating whether this should be added to First, we rejected Regarding whether the converter should be part of We might consider moving those converters to theme-specific assemblies in the future. If we do so, it will be for all converters. As such, this API is accepted as-is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
What does the pull request do?
This pull request refactors how indentation is applied to
TreeViewItem
elements in both the Fluent and Simple themes of Avalonia.What is the current behavior?
What is the updated/expected behavior with this PR?
It introduces a new converter,
TreeViewItemIndentConverter
, to handle indentation dynamically, replacing the previous static converters and hardcoded implementations.How was the solution implemented (if it's not obvious)?
Introduction of a new converter:
src/Avalonia.Controls/Converters/TreeViewItemIndentConverter.cs
: Added a newTreeViewItemIndentConverter
class implementingIMultiValueConverter
. It calculates the indentation based on theLevel
andIndent
values, returning aThickness
object.Updates to the Fluent theme:
src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml
: Replaced theTreeViewItemLeftMarginConverter
with the newTreeViewItemIndentConverter
. Updated theGrid.Margin
property in thePART_Header
element to use aMultiBinding
with the new converter. [1] [2]Updates to the Simple theme:
src/Avalonia.Themes.Simple/Controls/TreeViewItem.xaml
: Removed theLeftMarginConverter
and replaced it with aTreeViewItemIndent
resource. Updated theGrid.Margin
property in thePART_Header
element to use aMultiBinding
with the newTreeViewItemIndentConverter
. [1] [2]Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues
#18311