Applying DataTemplate to a Grid
14,563
You cannot apply DataTemplates
to panels (e.g. Grid).
If you just want that template placed somwhere then you can use a ContentControl
and set it as the ContentTemplate
via StaticResource
.
(ContentControl.Content
needs to be set to something, otherwise the ContentTemplate
is not applied, if there is no real "content" setting the Template
instead should work as well.)
Author by
mauryat
Updated on July 01, 2022Comments
-
mauryat almost 2 years
How is a
DataTemplate
applied to aGrid
?I have a
DataTemplate
named DataGrid_Template in myResources.xaml
file that I would like to apply to aGrid
in View.xaml.
Resources.xaml<ResourceDictionary ... > <DataTemplate x:Key="DataGrid_Template"> <Grid> <Grid.RowDefinitions ... /> <DockPanel ... /> <DataGrid ... /> </Grid> </DataTemplate> </ResourceDictionary>
View.xaml<UserControl ... > <Grid /> <!-- want to apply DataGrid_Template to this --> </UserControl>
I tried using theGrid
propertyTemplatedParent
, but that seems to be a read-only property.