0

I have a listview for which i have implemented grouping and have defined an expander inside the groupstyle as shown below :

<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}">
                                            <Expander IsExpanded="True" >
                                                <Expander.Header>
                                                    <DockPanel>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                                                        <TextBlock FontWeight="Bold" Text=" Items"/>
                                                    </DockPanel>
                                                </Expander.Header>
                                                <Expander.Content>
                                                    <ItemsPresenter />
                                                </Expander.Content>
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                </ListView.GroupStyle>

I want to modify the expander such that only one is expanded and the rest are collapsed if more than one are there and also if i want to programmatically expand any one of the expanders i.e. suppose i add an object from cs and want to show that expander opened, it should be possible, any suggestions ?? Thanks in advance

Edit : The code to bind the listview and the group :

CollectionViewSource viewSource = new CollectionViewSource { Source = TO_DOlst };
        viewSource.GroupDescriptions.Add(new PropertyGroupDescription("timeCategory"));
        lstView.ItemsSource = viewSource.View;

timecategory is a member of the class

Dannyboy
  • 165
  • 1
  • 3
  • 8

1 Answers1

0

You can Bind IsExpanded property by creating a boolean property in your class just like Name and define all Business rules in CS directly.

if(ItemsSource.Count() > 1)
  //set IsExpanded = false;
else
  // set only first item and so on.

Regards.

destined
  • 324
  • 1
  • 3
  • 9
  • thank you....i will try that.....and what if i programatically want to expand one of them, like when i add a new item to it, is it possible ?? – Dannyboy Sep 06 '12 at 03:52
  • also, i have added the code i use to bind in my edit, how how do i bind the expander to isexpanded, if it is a part of the class, wont there be many values for it, one per item ?? – Dannyboy Sep 06 '12 at 04:21