我如何wpf treeview删除边框

时间:2016-10-25 08:08:38

标签: wpf treeview

enter image description here

我想表明,当我选择treeViewItem时,treeViewItem会更改背景。我删除了TreeView边框。但是离开了TreeView背景。如何删除红色圆圈图像中的空格蓝色?

我的XAML代码是:

<UserControl.Resources>
    <Style x:Key="LibraryTreeViewItemStyle"
           TargetType="{x:Type TreeViewItem}">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="true">
                <Setter Property="Foreground" Value="Black" />
            </Trigger>
            <Trigger Property="IsSelected" Value="false">
                <Setter Property="Foreground" Value="White" />
            </Trigger>
        </Style.Triggers>
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Green" />
        </Style.Resources>
    </Style>
</UserControl.Resources>

<TreeView x:Name="tv" HorizontalAlignment="Left" Height="195" VerticalAlignment="Top" Width="187"  Background="#FF213757"  ItemContainerStyle="{StaticResource LibraryTreeViewItemStyle}" BorderBrush="#FF1B1919" >

4 个答案:

答案 0 :(得分:3)

我刚刚在XAML的BorderThickness="0"调用中使用了<TreeView *STUFF* ></TreeView>

(我的Xaml代码作为参考)

    <TreeView x:Name="tvReports" BorderThickness="0" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Auto" Visibility="Hidden"  Background="AliceBlue"></TreeView>

答案 1 :(得分:0)

将TreeView填充更改为0(默认值为1):

<TreeView Padding="0" ...

答案 2 :(得分:0)

此解决了我的问题Treeview内部的Scrollviewer具有边框厚度

<Style TargetType="TreeView">
                        <Style.Setters>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="TreeView">
                                        <Border Name="Border" Background="Transparent" BorderThickness="0"
                                                >
                                            <ScrollViewer Background="Transparent" Focusable="False"
                                                          CanContentScroll="False"
                                                          BorderThickness="0">
                                                <ItemsPresenter />
                                            </ScrollViewer>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style.Setters>
                    </Style>

答案 3 :(得分:0)

因为边框属于 ScrollViewer,只需将其重叠设置 Margin="-1"