2011-11-25 28 views
1

我想顯示我的用戶控制行內的細節。用戶控制裏面的datagrid行detalis

我有一個複雜的數據結構,不能顯示datagrid中的所有項目(只是幾個),所以我想打開另一個控件並在行內顯示它。我以前創建(設計)它。我不是動態創建它的。

有沒有辦法實現它?

我正在與C#和WPF合作開發桌面應用程序。

我希望能夠使用它像:

<DataGrid.RowDetailsTemplate> 
     <DataTemplate> 
     // <StackPanel Orientation="Horizontal" Margin="20,0,0,0"> 
     //  <TextBlock Text="Category:" FontWeight="Bold"/> 
     //  <ComboBox IsEditable="True" 
     //     ItemsSource="{Binding Source={x:Static Data:CheckBook.Categories}}" 
     //     Text="{Binding Category}" /> 
     //  </StackPanel> 
     <MyControl ItemsSource="blabla"> 
     </DataTemplate> 
    </DataGrid.RowDetailsTemplate> 

回答

0

實現,最簡單的方法是使用下面的:

請注意,如果你需要的是與你的用戶/自定義控件一個列,它很可能使使用不便更有意義。像ListBox和定製的ItemTemplate一樣,因爲它更輕。

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <DataGrid> 
      <DataGrid.Columns> 
       <DataGridTemplateColumn> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
          **...your user control goes here** 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
       </DataGridTemplateColumn> 
      </DataGrid.Columns> 
     </DataGrid> 
    </Grid> 
</Window> 
0

這聽起來像你描述的分層數據結構。 (具有父/子或主/明細關係的數據)

Microsoft提供有關在其中的Data Templating Overview中顯示WPF中的分層數據的指導。具體而言,這包括here