2012-05-16 30 views
1

我試圖儘可能使用數據綁定來創建我的gui。因爲我有收集頻道,也有步驟列表。我知道想要的是結合這些藏品XAML元素,並讓他們顯示在下面的順序:wpf中observablecollection的數據綁定,並以特殊順序填充gui

Channel1 step1 step2 step3 step4 
Channel2 step1 step2 step3 step4 

我嵌套ItemsControls這樣試了一下:

<ItemsControl ItemsSource="{Binding Path=channels}"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <ItemsControl ItemsSource="{Binding Path=steps}"> 
        <ItemsControl.ItemTemplate> 
         <DataTemplate> 
          <GUI:stepAnalog></GUI:stepAnalog> 
         </DataTemplate> 
        </ItemsControl.ItemTemplate> 
       </ItemsControl> 
      </StackPanel> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

但我所實現的是什麼像訂購元素,如:

channel1 step1 step2 step3 channel2 step1 step2 step3 

channel1 
step1 
step2 
step3 
channel2 
step1 
step2 
step3 

在使用數據綁定的wpf中有沒有解決方案,還是我必須通過遍歷元素並將它們放置在程序中來編程?

回答

1

Theres總是一個解決方案,它只是一個找到合適的問題!

我建議你ItemsControls的ItemsPanel像這樣玩:

這允許您指定如何在項目控制中的項目奠定了,你仍然可以使用您的DataTemplate來定義它們如何顯示

相關問題