Answered TreeView in ListView's template

  • Saturday, December 03, 2005 3:41 AM
     
     
    I'm having trouble customizing the ListView to my needs. The truth is, I have no idea where to start.

    I want to create a control that looks like Microsoft Money 2006's Accounts listview. Here's a screenshot:

    http://img231.imageshack.us/my.php?image=money4kd.png

    Does anyone have some templates or examples they can give me?

    Thanks,
    Johann MacDonagh

All Replies

  • Tuesday, December 20, 2005 6:05 AM
     
     Answered

            I am not sure which is the best way to realize you scenario. The following example is built on on ListView and Expander, I hope it could be helpful.

          Note: this example is based on Beta 2 , if you are using earlier build, maybe you need to do some changes to make it work.

              <?Mapping XmlNamespace="sys" ClrNamespace="System" Assembly="mscorlib"?>
              <?Mapping XmlNamespace="group" ClrNamespace="System.Windows.Data" Assembly="PresentationFramework"?>
              <?Mapping XmlNamespace="collections" ClrNamespace="System.Collections" Assembly="mscorlib"?>
              <StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                    xmlns:s='collections' xmlns:g='group' xmlns:p='sys'>
                 <StackPanel.Resources>
                    <CollectionViewSource x:Key='src'>
                       <CollectionViewSource.GroupDescriptions>
                          <g:PropertyGroupDescription PropertyName="Month"/>
                       </CollectionViewSource.GroupDescriptions>
                       <CollectionViewSource.Source>
                          <s:ArrayList>
                            <p:DateTime>2005/1/1</p:DateTime>
                            <p:DateTime>2005/2/2</p:DateTime>
                            <p:DateTime>2005/1/3</p:DateTime>
                            <p:DateTime>2005/3/4</p:DateTime>
                            <p:DateTime>2005/2/18</p:DateTime>
                            <p:DateTime>2005/1/12</p:DateTime>
                            <p:DateTime>2005/2/12</p:DateTime>
                            <p:DateTime>2005/1/20</p:DateTime>
                          </s:ArrayList>
                       </CollectionViewSource.Source>
                   </CollectionViewSource>
                </StackPanel.Resources>
                <ListView Name="lv2" ItemsSource='{Binding Source={StaticResource src}}'>
                   <ListView.GroupStyle>
                      <GroupStyle>
                         <GroupStyle.ContainerStyle>
                           <Style TargetType="{x:Type GroupItem}">
                              <Setter Property="Template">
                                <Setter.Value>
                                  <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <Expander>
                                      <Expander.Header>
                                        <TextBlock Text="{Binding Path=ItemCount}"/>
                                      </Expander.Header>
                                      <Expander.Content>
                                        <ItemsPresenter/>
                                      </Expander.Content>
                                    </Expander>
                                 </ControlTemplate>
                               </Setter.Value>
                             </Setter>
                          </Style>
                        </GroupStyle.ContainerStyle>
                      </GroupStyle>
                  </ListView.GroupStyle>
                <ListView.View>
                  <GridView>
                     <GridViewColumn Header="Day" DisplayMemberBinding="{Binding Path=Day}" Width="150"/>
                     <GridViewColumn Header="Month" DisplayMemberBinding="{Binding Path=Month}" Width="100"/>
                     <GridViewColumn Header="Year" DisplayMemberBinding="{Binding Path=Year}" Width="200"/>
                     <GridViewColumn Header="DayOfWeek" DisplayMemberBinding="{Binding Path=DayOfWeek}" Width="100"/>
                     <GridViewColumn Header="DayOfYear" DisplayMemberBinding="{Binding Path=DayOfYear}" Width="200"/>
                  </GridView>
                </ListView.View>
                <ListView.SelectedIndex>-1</ListView.SelectedIndex>
              </ListView>

            </StackPanel>

    Thanks.