2012-05-22 60 views
1

我需要有一个DataGrid有多行和3列。现在DataGrid的每个单元都显示一些信息(6到8个参数)和一个按钮。点击这个按钮后,弹出窗口显示出来。我们可以在WPF中的DataGrid的单元格内有一个网格吗?

现在为了显示DataGrid的单元格内的数据,我需要对齐它们并正在考虑使用Grid。如何实现这一点。

另外我该如何在单击按钮的单击事件时知道点击了哪个单元格按钮?

请帮忙。

回答

5

您可以添加DataGridTemplateColumn(S)到您的DataGrid,然后定义通常的数据模板列:

<DataGrid.Columns> 
    <DataGridTemplateColumn Header="Foo" Width="SizeToCells"> 
      <DataGridTemplateColumn.CellTemplate> 
       <DataTemplate> 
        <Grid> 
         ... 
         <Button Command="{Binding SomeCommand}" /> 
        </Grid> 
       </DataTemplate> 
      </DataGridTemplateColumn.CellTemplate> 
    </DataGridTemplateColumn> 
<DataGrid.Columns> 

现在有关单击事件。绑定您的网格与项目源。该源中的每个项目必须是具有任何ICommand属性的视图模型。将此属性绑定到单元格模板中的按钮命令,您将获得它。

相关问题