WPF TreeView multiple itemsSource

I want to show the following using wpf TreeView:

TreeView structure

My objects are different, there is no base class or interface, I have to define a HierarchicalDataTemplate for each element like STOP. I can only add one ItemSource "Deliveries", but I want to add pickups for this stop as well.

<!-- DELIVERY-->
<DataTemplate x:Key="DeliveryDataTemplate">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="DeliveryId"  Margin="3,3" />
        <TextBlock Text="{Binding DeliveryStatus}" VerticalAlignment="Center" Margin="5" />
        <TextBlock Background="{Binding StopStatus, Converter={StaticResource StatusConverter}}" Width="16" Height="16" />
    </StackPanel>
</DataTemplate>

<!-- STOP -->
<HierarchicalDataTemplate x:Key="StopTemplate"
                          ItemsSource="{Binding Deliveries}"
                          ItemTemplate="{StaticResource DeliveryTemplate}">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Stop"  Margin="3,3" />
        <TextBlock Text="{Binding StopId}" Margin="3,3" />
        <TextBlock Background="{Binding StopStatus, Converter={StaticResource StatusConverter}}" Width="16" Height="16" Margin="3,3"  />
    </StackPanel>
</HierarchicalDataTemplate>

<!-- ROUTE -->
<HierarchicalDataTemplate x:Key="RouteTemplate"
                          ItemsSource="{Binding Stops}"
                          ItemTemplate="{StaticResource StopTemplate}">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Route"  Margin="5,5" />
        <TextBlock Text="{Binding RouteId}" Margin="5,5" />
        <TextBlock Background="{Binding RouteStatus, Converter={StaticResource StatusConverter}}" Width="16" Height="16"  Margin="5,5" />
    </StackPanel>
</HierarchicalDataTemplate>

      

I have a set of routes, each route has Stops, each Stop has Deliveries and Pickups, each Deliver has its own items, each product has its own items, and so on ... How to solve this?

+3


source to share


1 answer


This sounds like a heterogeneous data source problem. I think this solution might be what you are looking for.



+2


source







All Articles