Search code examples
c#xamldatatemplategridcontrol

Apply or not a DataTemplate on the fly


I have a grid with a column datatemplate that I'd like to apply (or not) based on a checkbox tick in it's header.

Can't figure out how to handle this though. Would there be an enabled flag somewhere?

<dxg:GridControl>
    <dxg:GridControl.Columns>
        <dxg:GridColumn>
            <dxg:GridColumn.HeaderTemplate>
                <DataTemplate>
                    <CheckBox Name="StatusCheck" Content="Status" />
                </DataTemplate>
            </dxg:GridColumn.HeaderTemplate>
            <dxg:GridColumn.CellTemplate>
                <DataTemplate>
                    ...
                </DataTemplate>
            </dxg:GridColumn.CellTemplate>

Thank you in advance!


Solution

  • It seems like you are using a third party control (dxg:...). Therefore, you have to look up it's documentation to be sure.

    Most templated Controls have a TemplateSelector property for their datatemplates, where you can pass a DataTemplateSelector.

    If that is not the case, you can still put a custom Control into the header, that changes it's visualization depending on your data.

    Third option is, to just set your checkboxes visibility depending on your data.