我的用户界面中有一个充满圆角的树视图,所以我希望树视图能够匹配。是否可以在 xaml 中将树视图的边框更改为圆角?
我考虑过隐藏边框并将树视图放在圆角矩形内,但这会损失空间并且看起来不优雅。
有任何想法吗?
覆盖树视图的控件模板以更改边框。如果您有Expression Blend,它可以轻松地为您提取默认的控制模板,然后您只需在最顶部的边框上拍打适当的半径即可。
或者,查看这篇 MSDN 文章,其中包含以下树视图控件模板:
<Style x:Key="{x:Type TreeView}" TargetType="TreeView">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<Border
Name="Border"
CornerRadius="1"
Background="{StaticResource WindowBackgroundBrush}"
BorderBrush="{StaticResource SolidBorderBrush}"
BorderThickness="1" >
<ScrollViewer
Focusable="False"
CanContentScroll="False"
Padding="4">
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
只需更改外边框以具有更强的边框半径就可以达到您想要的效果。
| 归档时间: |
|
| 查看次数: |
4690 次 |
| 最近记录: |