2010-03-03 110 views
0

我有以下領域:WPF數據網格結合

public class FileInformation 
{ 
public String FileName; 
public String CreatedBy; // name of user who created the file 
public String CreatedComments; 
public String CreatedDate; 
public String EditedBy; // name of user who last edited the file 
public String EditedComments; 
public String EditedDate; 
} 

public class Folder 
{ 
public List<FileInformation> Files {get;set} 
} 

我想有一個WPF DataGrid和綁定在「文件夾」類,以它的文件列表.....這是很容易,如果我想有一個標準的方式顯示的數據.....但我想把它通過以下方式顯示:

alt text http://i49.tinypic.com/nbua94.jpg

什麼我必須做的,有顯示的數據的任何想法通過這種方式 ?

回答

0

做到這一點最簡單的方法是:

  • 從綁定提取一個的CollectionView:

CollectionView cv = (CollectionView)(CollectionView)CollectionViewSource.GetDefaultView(_grid.ItemsSource);

  • 基於filename創建一個組cv.GroupDescriptions.Add(new PropertyGroupDescription("FileName"));

    • 在網格中創建一個GroupStyle,以您希望的方式顯示Gorup。

    <GroupStyle> 
         <GroupStyle.ContainerStyle> 
         <Style TargetType="{x:Type GroupItem}"> 
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="{x:Type GroupItem}"> 
             <Expander IsExpanded="True" Header={Binding Name}> 
              <ItemsPresenter/> 
             </Expander> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
         </GroupStyle.ContainerStyle> 
        </GroupStyle> 
    </DataGrid.GroupStyle> 
    

    所呈現的風格不會didsplay完全一樣的屏幕截圖展示,但在此基礎上土特產品的信息可以自定義的內容,以滿足您的需求...