views:

59

answers:

0

Hi I am writting an application using WPF MVVM and I added an accordion menu and inside the accordion I want to display a list of application. so basically my accordion menu would have categories as a header and the items inside the accordion would be my application.

so we would have something like this

categorie 1
-->application 1
-->application 2
categorie 2
-->application3
categorie 3
-->application 4
-->application 5
-->application 6
etc.

This is my XAML for the display of the accordion

<UserControl.Resources>
    <CollectionViewSource
  x:Key="QuickpathData" 
  Source="{Binding Path=AllQPaths}"
  >

       <CollectionViewSource.SortDescriptions>
           <scm:SortDescription PropertyName="DisplayName" Direction="Ascending" />
        </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>

    <CollectionViewSource
  x:Key="CategorieData" 
  Source="{Binding Path=AllCategories}"
  >


    </CollectionViewSource>


    <DataTemplate x:Key="QuickpathDataTemplate">
        <StackPanel >
            <Label Focusable="True" FontSize="12" FontWeight="Bold" Foreground="White">
                <Label.Content>
                    <Binding Path="QuickpathName" />
                </Label.Content>
            </Label>
        </StackPanel>
    </DataTemplate>

</UserControl.Resources>

<StackPanel>
    <WPFToolkit:Accordion ItemsSource="{Binding Source={StaticResource CategorieData}}" HorizontalAlignment="Stretch" SelectionMode="One">

        <WPFToolkit:Accordion.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Categorie}" />
            </DataTemplate>
        </WPFToolkit:Accordion.ItemTemplate>

        <WPFToolkit:Accordion.ContentTemplate>
            <DataTemplate>
                <ListView ScrollViewer.CanContentScroll="False" ScrollViewer.VerticalScrollBarVisibility="Hidden"
            Background="#999"
            BorderBrush="White" 
            ItemContainerStyle="{StaticResource QPathItemstyle}"
            ItemsSource="{Binding Source={StaticResource QuickpathData}}"
            ItemTemplate="{StaticResource QuickpathDataTemplate}" BorderThickness="0" MinWidth="2000">                  
                </ListView>

            </DataTemplate>
        </WPFToolkit:Accordion.ContentTemplate>
    </WPFToolkit:Accordion>
</StackPanel>

AllQpaths would be my list of application and AllCategories my list of categories

This is the code to fill up both list

Private Sub CreateAllQPaths()
        Dim allC As List(Of CategorieViewModel) = ( _
       From cat In _categorieRepository.GetCategories() _
      Select New CategorieViewModel(cat, _categorieRepository)).ToList()

        Dim all As List(Of QPathViewModel) = ( _
          From cust In _qPathRepository.GetQPaths() _
        Select New QPathViewModel(cust, _qPathRepository)).ToList()

        For Each qvm As QPathViewModel In all
            AddHandler qvm.PropertyChanged, AddressOf OnQPathViewModelPropertyChanged
        Next qvm

        Me.AllCategories = New ObservableCollection(Of CategorieViewModel)(allC)
        Me.AllQPaths = New ObservableCollection(Of QPathViewModel)(all)
        AddHandler Me.AllQPaths.CollectionChanged, AddressOf OnCollectionChanged

    End Sub

Qpathviewmodel would be my viewmodel for the applications.


This basically gives me all the list of categories as the accordion menu headers and it displays all the application inside each category. I can understand why, but I can't figure out how to place each application to their corresponding category, Can anyone please help?

thank you