2008-12-23 24 views
1

我在綁定到自定義類的列表的列表視圖中顯示多行數據。自定義類有一個名爲type的屬性。允許的類型數量是有限的,我想限制用戶通過從組合框中選擇進行更改。我嘗試添加一個組合框到基類,但沒有顯示爲列表視圖中的組合框。如何在綁定時在ListView中顯示組合框?

回答

0

在線發現並且似乎是開始使用DataTemplates的一個很好的起點。

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/749c8e84-3af3-4ec9-90b1-297d684025e7/

<Window x:Class="Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="Window1" Height="300" Width="300"> 

<Window.Resources> 

    <XmlDataProvider x:Key="MyData" XPath="/Info"> 
     <x:XData> 
      <Info xmlns=""> 
       <Item ID="123" Catalog="Category1"/> 
       <Item ID="456" Catalog="Category2"/> 
       <Item ID="789" Catalog="Category3"/> 
      </Info> 
     </x:XData> 
    </XmlDataProvider> 

    <CollectionViewSource x:Key='src' Source="{Binding Source={StaticResource MyData}, XPath=Item}" /> 

</Window.Resources> 

<Grid> 

    <ListView Name="mylist" ItemsSource="{Binding Source={StaticResource src}}"> 

     <ListView.View> 

      <GridView> 

       <GridViewColumn Header="Catalog" Width="100"> 

        <GridViewColumn.CellTemplate> 
         <DataTemplate> 
          <ComboBox Name="mycombo" SelectedValue="{Binding [email protected]}"> 
           <ComboBoxItem>Category1</ComboBoxItem> 
           <ComboBoxItem>Category2</ComboBoxItem> 
           <ComboBoxItem>Category3</ComboBoxItem> 
          </ComboBox> 
         </DataTemplate> 

        </GridViewColumn.CellTemplate> 

       </GridViewColumn> 

       <GridViewColumn Header="ID" Width="100" DisplayMemberBinding="{Binding [email protected]}" /> 

      </GridView> 

     </ListView.View> 

    </ListView> 

</Grid> 

0

您需要使用DataTemplate。

網上有很多教程。

相關問題