开发者

WPF DataGrid as regular Grid

Can I use the WPF DataGrid control in the same way I use开发者_运维知识库 a regular Grid?

How can I do the following but using a DataGrid instead of using the standard Grid?

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="182" />
        <ColumnDefinition Width="360" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Label Grid.Row="0" Grid.Column="0">
        Configuration Software:
    </Label>
    <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Software.Name}"/>
</Grid>


I'm not sure what you mean by "the same way", but if you expect to represent the data in XAML like you did with the example and manually assign the value for each cells (like the old days, believe me I too have had times when I wish this is possible), you can't.

The data should be represented in a class instead, a collection of this class is then bound to the data grid. If you need to customise display for every row/cell you would have to work with the underlying template (which sometimes could be lot of work).


No, the WPF Datagrid is a control used to show data that is bound to it.

The WPF Grid control is a layout container.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜