Search code examples
c#xamlwindows-runtimewindows-store-apps

How to set the control template in C#


How do you set the .Template property of an element (e.g. a FlipViewItem in my case) using C# code to a predefined one in my StandardStyles.xaml

This is the template if it's relevant:

<ControlTemplate x:Key="DocumentFlipViewItemControlTemplate" TargetType="FlipViewItem">
    <Grid Width="160" HorizontalAlignment="Left">
        <MyProject:DocumentTabControl Name="MainDocumentTabControl"/>
    </Grid>
</ControlTemplate>

Please note this is a different question from How to set Control Template in code? - that question creates a template on the fly and then assigns it to the control, I just want to set a predefined template.


Solution

  •     <Style x:Key="DocumentFlipViewItemStyle" TargetType="FlipViewItem" >
                <Setter Property="Template" Value="{StaticResource DocumentFlipViewItemControlTemplate}"/>
        </Style>