Files
Shrlalgo.RvKits/Melskin/Controls/TreeGrid.xaml
2026-02-12 21:29:00 +08:00

73 lines
4.7 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:assists="clr-namespace:Melskin.Assists"
xmlns:controls="clr-namespace:Melskin.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type controls:TreeGrid}">
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
<Setter Property="assists:ControlAssist.CornerRadius" Value="4" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:TreeGrid}">
<Grid>
<Border Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}">
<Border.OpacityMask>
<VisualBrush>
<VisualBrush.Visual>
<!-- 定义遮罩形状:黑色代表可见区域,圆角与外部一致 -->
<Border
Background="Black"
CornerRadius="{Binding CornerRadius, RelativeSource={RelativeSource AncestorType=Border}}"
Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Border}}"
SnapsToDevicePixels="True"
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Border}}" />
</VisualBrush.Visual>
</VisualBrush>
</Border.OpacityMask>
<DockPanel>
<!-- 1. 表头区域,放置在顶部 -->
<!-- - 用 ScrollViewer 包裹以同步滚动 -->
<!-- - 隐藏自己的滚动条,因为它只是一个“跟随者” -->
<ScrollViewer
Background="Transparent"
DockPanel.Dock="Top"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Disabled"
x:Name="PART_HeaderScrollViewer">
<GridViewHeaderRowPresenter Columns="{Binding Columns, RelativeSource={RelativeSource TemplatedParent}}" />
</ScrollViewer>
<!-- 2. 内容区域,占据剩余空间 -->
<!-- - 将所有相关属性从外层 TreeGrid 传递给内部的 TreeView -->
<TreeView
Background="{DynamicResource ControlBackgroundNormalBrush}"
BorderThickness="0"
ItemContainerStyle="{Binding ItemContainerStyle, RelativeSource={RelativeSource TemplatedParent}}"
ItemTemplate="{Binding ItemTemplate, RelativeSource={RelativeSource TemplatedParent}}"
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
assists:ControlAssist.CornerRadius="0"
x:Name="PART_ContentTreeView">
<!-- 可选:为了性能,可以启用虚拟化 -->
<TreeView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</TreeView.ItemsPanel>
</TreeView>
</DockPanel>
</Border>
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}"
IsHitTestVisible="False" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>