Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:37:14+00:00 2026-06-16T03:37:14+00:00

I have multiple UserControl XAML files that use a similar structure. I want to

  • 0

I have multiple UserControl XAML files that use a similar structure. I want to remove this duplication and thought to use a Style that overrides the Template of the UserControl (and then use ContentPresenter for the custom part).

But apparently the Template of a UserControl can’t be overwritten.

How do I this the clean way? Derive from something else then UserControl?

<UserControl x:Class="Class1">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <sdk:Label Grid.Row="0" Content="Title1" Style="{StaticResource Header1}" />
    <Border Grid.Row="1">
    ...
</UserControl>

<UserControl x:Class="Class2">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <sdk:Label Grid.Row="0" Content="Title2" Style="{StaticResource Header1}" />
    <Border Grid.Row="1">
    ...
</UserControl>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:37:15+00:00Added an answer on June 16, 2026 at 3:37 am

    You could define a custom control like this. (I’m not sure if you need to specify the Title separate from the content, but here it is just in case.)

    public class MyControl : ContentControl
    {
        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(string), typeof(MyControl), new PropertyMetadata(null));
    
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }
    
        // ... other properties ...
    }
    

    Then define its template:

    <ControlTemplate x:Key="MyControlTemplate" TargetType="mynamespace:MyControl">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <sdk:Label Grid.Row="0" Content="{TemplateBinding Title}" Style="{StaticResource Header1}" />
            <Border Grid.Row="1">
                <ContentPresenter />
            ...
        </Grid
    </ControlTemplate>
    

    You could then define a default style, as shown here. (Alternatively, you could give it an x:Key and explicitly set the style each time you use MyControl. You could also just set the Template property each time you use MyControl, instead of specifying this Style at all.)

    <Style TargetType="mynamespace:MyControl">
        <Setter Property="Template" Value="{StaticResource MyControlTemplate}" />
    </Style>
    

    Then to use it:

    <mynamespace:MyUserControl Title="Title1">
        <!-- Content here -->
    </mynamespace:MyUserControl>
    
    <mynamespace:MyUserControl Title="Title2">
        <!-- Content here -->
    </mynamespace:MyUserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl (and background ViewModel) that I use across multiple projects -
I have a UserControl that I want to include in a page multiple times
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
So I have a button on a WinRT UserControl that I want to increase
I have a view named Work.xaml. This Work.xaml contains multiple WorkSkeleton.xaml. The Work.xaml's ViewModel
I have created my first asp.net UserControl that I will use in several places
So I want to have multiple tabs with a usercontrol in it, depending on
I have a user-control containing this XAML <UserControl x:Class=QA.JobListControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=using:QA xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
I have multiple UpdatePanels on a webpage, one inside UserControl (Purple ColorBox as show
I have a growing application with multiple usercontrols, windows, etc that all send a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.