Wpf 从列表视图顶部隐藏HeaderContent
我有一个Wpf 从列表视图顶部隐藏HeaderContent,wpf,xaml,mahapps.metro,Wpf,Xaml,Mahapps.metro,我有一个 <DockPanel> <!-- Header --> <Button DockPanel.Dock="Top" Command="{Binding CreateAccountCommand}" Margin="{StaticResource ControlMargin}" Style="{StaticResource IconButtonStyle}"> <StackPanel>
<DockPanel>
<!-- Header -->
<Button DockPanel.Dock="Top" Command="{Binding CreateAccountCommand}" Margin="{StaticResource ControlMargin}" Style="{StaticResource IconButtonStyle}">
<StackPanel>
<MahAppsIconPacks:PackIconFontAwesome Kind="Pencil" />
<TextBlock>create account</TextBlock>
</StackPanel>
</Button>
<!-- Accounts list -->
<ListView SelectionMode="Single" SelectedIndex="0" ItemsSource="{Binding AccountViewModels}" SelectedItem="{Binding SelectedItem}" Style="{StaticResource AccountsList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<LocalViews:AccountView Margin="{StaticResource ControlMargin}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListView>
</DockPanel>
您是否使用了
ListView
的任何查看功能?(例如GridView等,我认为这是默认值。在这种情况下,分隔符可能是标题部分,但为空)。如果没有,请尝试使用列表框。默认情况下,它没有标题
编辑:我刚刚检查了这个理论,但似乎我根本无法复制你的问题。下面是一个列表框,您已经获得了您的代码(以及一个良好度量的列表视图):
项目1
项目2
项目3
这可能是Windows7上的不同主题,但是,我使用的是Windows10
我相信这是MahApps模板的结果。这不是标准WPF ListView的默认行为
您必须调整MahApps模板才能删除它。
大概是这样的:
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}">
<Setter Property="BorderThickness" Value="0" />
</Style>
MahApps代码和资源都是开源的。我认为您遇到的特殊问题是由边界厚度设置器造成的:
您指的是WPF应用程序上的调试工具栏visual studio覆盖吗?如果是这样,您可以根据以下问题将其停用:不,不是。我将在一秒钟内添加一个屏幕截图。不,不使用ListView。View
我已用我的完整代码和屏幕截图更新了问题。您是否尝试使用listbox?正如另一个答案提到的,这与listView标题的样式有关。Header是您未使用的ListView的一项功能,因此您可以使用ListBox。是的,就是它。如果你把它作为答案贴出来,我会接受的。然而,它引入了另一个问题,滚动,但这是一个不同的主题。这就是上面的答案!很高兴它修好了。我总是发现在这些地方,尤其是在水平方向上,需要几次尝试才能让滚动正常工作。
<Window.Resources>
<x:Array x:Key="Items" Type="sys:String">
<sys:String>Item 1</sys:String>
<sys:String>Item 2</sys:String>
<sys:String>Item 3</sys:String>
</x:Array>
</Window.Resources>
<StackPanel Margin="20">
<TextBlock Text="ListBox:"/>
<ListBox Height="100" ItemsSource="{StaticResource Items}" BorderBrush="Transparent">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
<TextBlock Text="ListView:"/>
<ListView Height="100" ItemsSource="{StaticResource Items}" BorderBrush="Transparent">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListView>
</StackPanel>
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}">
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style x:Key="MetroListView" TargetType="{x:Type ListView}">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="AlternationCount" Value="2" />
<Setter Property="Background" Value="{DynamicResource WhiteBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BlackBrush}" />
<Setter Property="BorderThickness" Value="0 1 0 0" />