Is it possible to use a static resource inside a DataTemplate definiton?

GaetanFGaetanF USMember ✭✭✭

Hello guys,

I was wondering if it was possible to set the content of a data template to a static resource from the resource dictionary, something like that:

<ResourceDictionary>
    <Grid x:Key="Layout1"
          ...
    </Grid>
    <Grid x:Key="Layout2"
          ...
    </Grid>

    <DataTemplate x:Key="Layout1DataTemplate"
                  SomePropertyToSetTheContent="{StaticResource Layout1}" />
    <DataTemplate x:Key="CellLayout1DataTemplate">
        <ViewCell View="{StaticResource Layout1}" />
    </DataTemplate>

    <DataTemplate x:Key="Layout2DataTemplate"
                  SomePropertyToSetTheContent="{StaticResource Layout2}" />
    <DataTemplate x:Key="CellLayout2DataTemplate">
        <ViewCell View="{StaticResource Layout2}" />
    </DataTemplate>

    <DataTemplatesNameSpace:LayoutDataTemplateSelector x:Key="LayoutSelector"
                                                       Layout1DataTemplate="{StaticResource Layout1DataTemplate}"
                                                       Layout2DataTemplate="{StaticResource Layout2DataTemplate}"
                                                       CellLayout1DataTemplate="{StaticResource CellLayout1DataTemplate}"
                                                       CellLayout2DataTemplate="{StaticResource CellLayout2DataTemplate}"
</ResourceDictionary>

I could not find documentation nor help about that. Is that even possible?

Sign In or Register to comment.