开发者

List the items in listview according to groups, the data is taken from observable collection

i hav one class which stores file information with namelist as itz observableCollection

Imports System.Collections.ObjectModel

Public Class NameList Inherits ObservableCollection(Of FileInfo)

' Methods
Public Sub New()
    MyBase.Add(New FileInfo("Willa", "Cather", "warning", "err 1"))
    MyBase.Add(New FileInfo("Isak", "Dinesen", "warning", "err 1"))
    MyBase.Add(New FileInfo("Victor", "Hugo", "warning", "err 1"))
    MyBase.Add(New FileInfo("Jules", "Verne", "warning", "err 3"))
    MyBase.Add(New FileInfo("Victor", "Hugo", "warning", "err 1"))
    MyBase.Add(New FileInfo("Jules", "Verne", "warning", "err 3"))
End Sub

End Class

Public Class FileInfo

Public _name As String
Public _path As String
Public _image As String
Public _errorGrp As String

Public Property ImageIcon() As String
    Get
        Return _image
    End Get
    Set(ByVal value As String)
        _image = value
    End Set
End Property

Public Property PathFile() As String
    Get
        Return _path
    End Get
    Set(ByVal value As String)
        _path = value
    End Set
End Property

Public Property Name() As String
    Get
        Return _name
    End Get
    Set(ByVal value As String)
        _name = value
    End Set
End Property

Public Property ErrorGroup As String
    Get
        Return _errorGrp
    End Get
    Set(ByVal value As String)
        _errorGrp = value
    End Set
End Property

Public Sub New(ByVal fileName As String, ByVal filePath As String, ByVal image As String, ByVal errorGrp As String)
    Name = fileName
    PathFile = filePath
    ImageIcon = image
    ErrorGroup = errorGrp
End Sub

End Class

i need to bind this to the xaml listview item which will be grouped according to errorGroup i code which i have tried is

<Window.Resources >
    <mydata:NameList x:Key="NameListData"/>

  <!--  <DataTemplate x:Key="IconListViewItem" >
        <StackPanel Orientation="Horizontal" >
             <Image Source="/listViewGroupin;component/Images/ViewType.jpg" Height="19" Width="25" ></Image>
            <TextBlock Foreground="DarkBlue" Text="{Binding ImageIcon}"/>
            <TextBlock Foreground="DarkBlue" Text="{Binding Name}"/>
        </StackPanel>
    </DataTemplate>-->

    <CollectionViewSource x:Key='src' 
                      Source="{Binding Source={StaticResource NameListData}}">
        <CollectionViewSource.GroupDescriptions>
           <!-- <PropertyGroupDescription PropertyName="ErrorGroup" />-->
            <PropertyGroupDescription PropertyName="ErrorGroup"/>
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

</Window.Resources>
<Grid>
    <ListView ItemsSource="{Binding Source={StaticResource src}}"
        IsSynchronizedWithCurrentItem="True" >
        <ListView.GroupStyle >
            <GroupStyle >
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Margin" Value="0,0,0,5"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GroupItem}">

                                    <GroupBox BorderBrush="Transparent"  >
                                        <GroupBox.Header >
                                            <StackPanel Orientation="Horizontal" >

                                                <TextBlock Text="{Binding Name}" 
                               Margin="5,0,0,0" Width="100"/>
                                                <Border Height=".2" Width="300" Background="Blue"  ></Border>
                                            </StackPanel>
                                        </GroupBox.Header>
                                    </GroupBox>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </ListView.GroupStyle>

        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="Width" Value="Auto" />
                <Setter Property="FontSize" Value="10.4"  />
            </Style>
        </ListView.ItemContainerStyle>

        <ListView.View  >
            <GridView AllowsColumnReorder="False">
                <GridViewColumn Width=" 250" Header="File" DisplayMemberBinding="{Binding Name }">
                </GridViewColumn>
                <GridViewColumn Header="Path" Width="350" DisplayMemberBinding="{Binding PathFile}">
                </GridViewColumn>
                <GridViewColumn Header="Error" Width="350"  DisplayMemberBinding="{Binding ErrorGroup}">
                <开发者_JS百科/GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>

it is giving me only group names and groups but not the item please help me


You have defined your ListView.GroupStyle as a GroupBox. GroupBox is a HeaderedContentControl. You have defined the Group Header, but you also need to define a placeholder for the items -

<GroupBox.Content>
   <ItemsPresenter />
</GroupBox.Content>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜