Click here to Skip to main content
15,902,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Right, I have been trying for hours to do this with not much success. What I want to do is when the user clicks a button it should load a listview with a few groups (with expanders in(style is below)) then add a few items to the groups with there being an item and a subitem with it. The following code is the XAML for the style of the listview items:
XML
<ListView Height="Auto" HorizontalAlignment="Left" Margin="1149,0,0,0" Name="dataTree" VerticalAlignment="Stretch" Width="292">
            <ListView.GroupStyle>
                <GroupStyle HidesIfEmpty="False">
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="GroupItem">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="GroupItem">
                                        <Expander IsExpanded="True">
                                            <Expander.Header>
                                                <Bold>
                                                    <TextBlock Text="{Binding Name}"/>
                                                </Bold>
                                            </Expander.Header>
                                            <ItemsPresenter/>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Parameter" Width="150" DisplayMemberBinding="{Binding Param}"/>
                    <GridViewColumn Header="Value" Width="100" DisplayMemberBinding="{Binding (originally 'group.Param' but not sure how this part works)}" />
                </GridView>
            </ListView.View>
        </ListView>

Basically I just want to know how to add groups and items to them to a listview in WPF. Much harder than windows forms. Thank you.
Posted

1 solution

Perhaps this like here could help you:
http://www.wpf-tutorial.com/listview-control/listview-grouping/[^]

And the documentation from MSDN is always worth a look:
http://msdn.microsoft.com/en-us/library/windows/apps/hh780627.aspx[^]

Hope this helps :)
 
Share this answer
 
Comments
Henry Hunt 21-Oct-13 13:46pm    
Perfect! Thank you
rajesh_kapure 3-Apr-14 4:01am    
I have gone through the example available on net related to grouping of listview item.
but we have to write the few lines of Code-behind code to tell WPF which property to group by.
I'm following MVVM pattern and i don't want to write the code in code behind file.
is there any way to do it the same in xaml only?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900