3
我想顯示使用WPF的TreeView以下:WPF TreeView的多個的ItemsSource
我的對象是不同的,不存在基類或接口,我必須定義爲每個項目,STOP一個HierarchicalDataTemplate例如我可以只添加一個ItemSource「Deliveries」,但我想爲此站點添加拾音器。
<!-- 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>
我有途徑的集合,每個路徑上有止損,每個站都有交付和皮卡,每個交付都有項目每個項目都有自己的項目等等......如何解決這個問題?
我覺得像休耕的解決辦法是那麼好 [WPF樹視圖數據綁定的層級與混合型數據] [提問]。 [提問]:HTTP://stackoverflow.com/questions/3673173/wpf-treeview-databinding-hierarchal-data-with-mixed-types/3673232#3673232 –