【问题标题】:How can I make a listview with individual row properties in XAML?如何在 XAML 中创建具有单个行属性的列表视图?
【发布时间】:2013-02-21 16:41:59
【问题描述】:

这是我想要做的一个模型:

https://www.dropbox.com/s/1nw78dqxuulvq73/Tree-01.png

这是我目前在 XAML 中的代码(尽管我认为我没有正确解决问题):

<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>

任何帮助将不胜感激! 谢谢!维达

【问题讨论】:

  • 我认为您应该使用 TreeView 而不是 ListViews,因为该图像显示的是树视图。
  • 我可以使用树视图单独控制行样式吗?我认为您可能适合格式化。
  • 这是另一个列表视图的例子,我认为这个列表视图比树更好,所以我很好奇你的想法:[链接]dropbox.com/s/9rg0fgckncmyhlc/ListEXdata-01.png

标签: wpf visual-studio-2010 xaml listview expression-blend


【解决方案1】:

我认为您可以使用 GroupStyle 和 CollectionViewSource 绑定来实现这一点。

参考示例图片上的名称, 您需要为您的“组”对象提供一个视图模型。在该视图模型中,您将拥有“Item”对象的 ObservableCollection。

然后,您将在窗口的“资源”部分中有一个 CollectionViewSource,它绑定到一组 Group 对象。然后为您的 ListBox 创建一个 GroupStyle,它可以针对 DataTemplates 来格式化您的 ListBox 中的数据。

我知道我可能没有很好地解释这一点,所以我提供了一个指向具有类似功能的项目的链接。

http://msdn.microsoft.com/en-us/library/ms752347.aspx

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    相关资源
    最近更新 更多