mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-26 11:17:55 +08:00
Merge pull request #596 from irihitech/treeview
Make TreeViewItem indentation easier
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<ResourceDictionary
|
<ResourceDictionary
|
||||||
xmlns="https://github.com/avaloniaui"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
|
xmlns:converters="clr-namespace:Semi.Avalonia.Converters"
|
||||||
x:CompileBindings="True">
|
x:CompileBindings="True">
|
||||||
|
|
||||||
<Design.PreviewWith>
|
<Design.PreviewWith>
|
||||||
@@ -40,8 +40,8 @@
|
|||||||
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
||||||
Background="{TemplateBinding Background}"
|
Background="{TemplateBinding Background}"
|
||||||
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
||||||
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
|
||||||
IsDeferredScrollingEnabled="{TemplateBinding (ScrollViewer.IsDeferredScrollingEnabled)}"
|
IsDeferredScrollingEnabled="{TemplateBinding (ScrollViewer.IsDeferredScrollingEnabled)}"
|
||||||
|
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
||||||
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
||||||
<ItemsPresenter
|
<ItemsPresenter
|
||||||
Name="PART_ItemsPresenter"
|
Name="PART_ItemsPresenter"
|
||||||
@@ -53,10 +53,6 @@
|
|||||||
</Setter>
|
</Setter>
|
||||||
</ControlTheme>
|
</ControlTheme>
|
||||||
|
|
||||||
<converters:MarginMultiplierConverter
|
|
||||||
x:Key="TreeViewItemLeftMarginConverter"
|
|
||||||
Indent="{StaticResource TreeViewItemIndent}"
|
|
||||||
Left="True" />
|
|
||||||
<ControlTheme x:Key="ToggleButtonTreeViewItemIconButton" TargetType="ToggleButton">
|
<ControlTheme x:Key="ToggleButtonTreeViewItemIconButton" TargetType="ToggleButton">
|
||||||
<Setter Property="Margin" Value="0" />
|
<Setter Property="Margin" Value="0" />
|
||||||
<Setter Property="Cursor" Value="Hand" />
|
<Setter Property="Cursor" Value="Hand" />
|
||||||
@@ -71,10 +67,10 @@
|
|||||||
Background="Transparent">
|
Background="Transparent">
|
||||||
<PathIcon
|
<PathIcon
|
||||||
Name="PART_ExpandIconPath"
|
Name="PART_ExpandIconPath"
|
||||||
Theme="{StaticResource InnerPathIcon}"
|
|
||||||
Classes="Small"
|
Classes="Small"
|
||||||
Data="{DynamicResource ExpanderIconData}"
|
Data="{DynamicResource ExpanderIconData}"
|
||||||
Foreground="{DynamicResource TreeViewItemIconDefaultForeground}">
|
Foreground="{DynamicResource TreeViewItemIconDefaultForeground}"
|
||||||
|
Theme="{StaticResource InnerPathIcon}">
|
||||||
<PathIcon.Transitions>
|
<PathIcon.Transitions>
|
||||||
<Transitions>
|
<Transitions>
|
||||||
<TransformOperationsTransition Property="RenderTransform" Duration="0.1" />
|
<TransformOperationsTransition Property="RenderTransform" Duration="0.1" />
|
||||||
@@ -110,16 +106,19 @@
|
|||||||
CornerRadius="{TemplateBinding CornerRadius}"
|
CornerRadius="{TemplateBinding CornerRadius}"
|
||||||
Focusable="True"
|
Focusable="True"
|
||||||
TemplatedControl.IsTemplateFocusTarget="True">
|
TemplatedControl.IsTemplateFocusTarget="True">
|
||||||
<Grid
|
<Grid Name="PART_Header" ColumnDefinitions="Auto, *">
|
||||||
Name="PART_Header"
|
<Grid.Margin>
|
||||||
Margin="{TemplateBinding Level, Mode=OneWay, Converter={StaticResource TreeViewItemLeftMarginConverter}}"
|
<MultiBinding Converter="{x:Static converters:TreeViewItemIndentConverter.Instance}">
|
||||||
ColumnDefinitions="Auto, *">
|
<Binding Path="Level" RelativeSource="{RelativeSource TemplatedParent}" />
|
||||||
|
<DynamicResource ResourceKey="TreeViewItemIndent" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Grid.Margin>
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
Name="PART_ExpandCollapseChevron"
|
Name="PART_ExpandCollapseChevron"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Padding="{DynamicResource TreeViewItemIconMargin}"
|
Padding="{DynamicResource TreeViewItemIconMargin}"
|
||||||
Focusable="False"
|
Focusable="False"
|
||||||
IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}"
|
IsChecked="{TemplateBinding IsExpanded,Mode=TwoWay}"
|
||||||
Theme="{StaticResource ToggleButtonTreeViewItemIconButton}" />
|
Theme="{StaticResource ToggleButtonTreeViewItemIconButton}" />
|
||||||
<ContentPresenter
|
<ContentPresenter
|
||||||
Name="PART_HeaderPresenter"
|
Name="PART_HeaderPresenter"
|
||||||
|
|||||||
22
src/Semi.Avalonia/Converters/TreeViewItemIndentConverter.cs
Normal file
22
src/Semi.Avalonia/Converters/TreeViewItemIndentConverter.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace Semi.Avalonia.Converters;
|
||||||
|
|
||||||
|
public class TreeViewItemIndentConverter : IMultiValueConverter
|
||||||
|
{
|
||||||
|
public static readonly TreeViewItemIndentConverter Instance = new();
|
||||||
|
|
||||||
|
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (values.Count > 1 && values[0] is int level && values[1] is double indent)
|
||||||
|
{
|
||||||
|
return new Thickness(indent * level, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Thickness(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user