Wpf 如何在XAML中创建具有单个行属性的listview?
下面是我希望做的一个模型: 以下是我目前在XAML中使用的代码(尽管我认为我没有正确地处理这个问题):Wpf 如何在XAML中创建具有单个行属性的listview?,wpf,visual-studio-2010,xaml,listview,expression-blend,Wpf,Visual Studio 2010,Xaml,Listview,Expression Blend,下面是我希望做的一个模型: 以下是我目前在XAML中使用的代码(尽管我认为我没有正确地处理这个问题): 15 黑色 试验 测试 测试 测试 测试 测试 试验 测试 测试 测试 测试 测试 测试 试验 任何帮助都将不胜感激! 谢谢VisDae我认为可以使用GroupStyle和CollectionViewSource绑定来实现这一点 参考样本图片上的名称, 您需要为“组”对象创建一个viewmodel。在该视图模型中,您将有一个“Item”对象的可观察集合 然后,在窗口的“资源”部分将有一
15
黑色
试验
测试
测试
测试
测试
测试
试验
测试
测试
测试
测试
测试
测试
试验
任何帮助都将不胜感激!
谢谢VisDae我认为可以使用GroupStyle和CollectionViewSource绑定来实现这一点 参考样本图片上的名称, 您需要为“组”对象创建一个viewmodel。在该视图模型中,您将有一个“Item”对象的可观察集合 然后,在窗口的“资源”部分将有一个CollectionViewSource,它绑定到组对象的集合。然后为ListBox创建一个GroupStyle,它可以以DataTemplates为目标来格式化ListBox中的数据 我知道我可能没有很好地解释这一点,所以我加入了一个指向具有类似功能的项目的链接
我认为您应该使用TreeView而不是ListView,因为该图像显示的是树视图。但是,我可以单独使用TreeView控制行样式吗?我认为您的格式设置可能是正确的。这是listview的另一个示例,我认为作为listview比作为树更好,尽管我对您的想法很好奇:[链接]
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CCListView.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListView Grid.Row="0" Grid.Column="0" ItemContainerStyle="{DynamicResource CustomListViewItemStyle}"
AlternationCount="2" Background="black" BorderThickness="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Title" DisplayMemberBinding="{Binding Path=ContInfo}" />
</GridView>
</ListView.View>
<ListViewItem>
<ListViewItem.FontSize>15</ListViewItem.FontSize>
<ListViewItem.Foreground>black</ListViewItem.Foreground>
<ListViewItem.Content>test</ListViewItem.Content>
</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
</ListView>
<ListView Grid.Row="0" Grid.Column="1" ItemContainerStyle="{DynamicResource CustomListViewItemStyle}"
AlternationCount="2" Background="black" BorderThickness="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Title" DisplayMemberBinding="{Binding Path=ContInfo}" />
</GridView>
</ListView.View>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
<ListViewItem>test</ListViewItem>
</ListView>
</Grid>