2010-11-04 55 views
0

細胞顯示多個項目,我有一個DataGrid是如下::WPF數據網格XML結合使用的DataTemplate

<wpfkit:DataGrid AutoGenerateColumns="False" 
     ItemsSource="{Binding}" 
     Width="Auto" 
     FrozenColumnCount="2" 
     SelectionMode="Extended" 
     CanUserAddRows="False" 
     x:Name="CommonPEGrid" 
     Loaded="CommonPEGrid_Loaded"> 
    <wpfkit:DataGrid.DataContext> 
     <XmlDataProvider Source="PE.xml" XPath="/Rows/Row"></XmlDataProvider> 
    </wpfkit:DataGrid.DataContext> 
</wpfkit:DataGrid> 

我從XML結合它的DataGrid。我的XML是如下::

<Rows> 
<Row Id="1"> 
    <Devices> 
    <Device>Device 1</Device> 
    <Device>Device 2</Device> 
</Devices> 
</Row> 

<Row Id="2"> 
    <Devices> 
    <Device>Device 3</Device> 
    <Device>Device 4</Device> 
    </Devices> 
</Row> 

我有一個定義的數據網格中的單元格一個DataTemplate如下::

<DataTemplate x:Key="MethodDefault"> 
    <ComboBox Margin="5" Height="25" ItemsSource="{Binding XPath=./Devices}" SelectedIndex="0" 
         > 
     <ComboBox.ItemTemplate> 
      <DataTemplate> 
       <TextBlock Text="{Binding XPath=./Device}"></TextBlock> 
      </DataTemplate> 
     </ComboBox.ItemTemplate> 
    </ComboBox> 
</DataTemplate> 

問題是,它始終只顯示1設備即組合框中的第一個設備。我想在下拉菜單中顯示所有設備。我不知道如何遍歷它們。我曾經認爲ComboBox會自動迭代,而不是這種情況。請幫幫我!!

回答

0

我可以找出答案。我發佈它假設它有助於某人!

<ComboBox ItemsSource="{Binding XPath=.//Devices}" SelectedIndex="0" > 

</ComboBox>