Shahin
Shahin

Reputation: 12843

WPF : Change DataTemplate of specific cell on DataGrid

I want to create a DataGrid like this :

enter image description here

User can add-remove columns at run-time. as shown in the picture I have to use DatePicker and checkbox and other controls on specific Cells .
How can I do it using WPF DataGrid ?
I think I have to change DataTemplate of particular cell but I don't know how
Is DataGrid appropriate control for this case ?

Upvotes: 0

Views: 702

Answers (1)

oddparity
oddparity

Reputation: 436

I would suggest putting all the filter controls(?) above the line below "suspended" in the header of the DataGrid. You can put in there whatever you want.

<Window.Resources>
    <DataTemplate x:Key="MySpecialHeaderTemplate">
        ...
    </DataTemplate>
</Window.Resources>
<Grid>
    <DataGrid>
        <DataGrid.Columns>
            <DataGridTextColumn HeaderTemplate="{StaticResource MySpecialHeaderTemplate}"
                    Binding="{Binding ...}" />
            <DataGridTextColumn HeaderTemplate="{StaticResource MySpecialHeaderTemplate}"
                    Binding="{Binding ...}" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

This is not easy, especially finding the ViewModel holding the data of those controls in the header, but it is possible.

Upvotes: 1

Related Questions