Xceed Toolkit for .NET Maui v2.0 Documentation
Xceed.Maui.Toolkit Assembly / Xceed.Maui.Toolkit Namespace / ContentControl Class / ContentTemplate Property
Example


In This Topic
    ContentTemplate Property
    In This Topic
    Gets or sets the DataTemplate that will be used to format the ContentControl's Content.
    Syntax
    'Declaration
     
    
    Public Property ContentTemplate As DataTemplate
    'Usage
     
    
    Dim instance As ContentControl
    Dim value As DataTemplate
     
    instance.ContentTemplate = value
     
    value = instance.ContentTemplate
    public DataTemplate ContentTemplate {get; set;}
    Example

    In the following example, the ContentControl binds its Content to UserObject.

    The ContentTemplate defines a template for displaying said Content & uses bindings to retrieve the Name & Goals values from UserObject

    <xctk:ContentControl Content="{Binding UserObject, Source={x:Reference _contentPage} }">
      <xctk:ContentControl.ContentTemplate>
        <DataTemplate>
          <xctk:Border Background="LightGray"
                       BorderBrush="Black"
                       BorderThickness="2"
                       CornerRadius="5">
            <HorizontalStackLayout>
              <Label Text="This is"
                     Margin="5"/>
              <Label Text="{Binding Name}"
                     TextColor="Red"
                     Margin="5"/>
              <Label Text="and he scored"
                     Margin="5"/>
              <Label Text="{Binding Goals}"
                     TextColor="Blue"
                     FontAttributes="Bold"
                     Margin="5"/>
              <Label Text="Goals."
                     Margin="5"/>
            </HorizontalStackLayout>
          </xctk:Border>
        </DataTemplate>
      </xctk:ContentControl.ContentTemplate>
    </xctk:ContentControl>
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also