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 6894155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:44:50+00:00 2026-05-27T06:44:50+00:00

I have a very large ControlTemplate (200+ lines) with many nested controls inside. I

  • 0

I have a very large ControlTemplate (200+ lines) with many nested controls inside. I need to reuse this template with a small change to one of these nested controls (visibility of a checkbox). Obviously I don’t want to copy-paste into a new ControlTemplate and just make that change because I’ll double the code base and if I make a common change to the template I’ll need to change both.

I’ve thought of three solutions that seem like they may work, but I don’t know enough about XAML (and especially refactoring XAML to know if these are possible)

  1. Extract the common XAML into a base ControlTemplate and ‘override’ the checkbox visibility in two new ControlTemplates (I place the override in quotations because I’m using C# speak – I’ve no idea if that makes sense in XAML!)

  2. Gain access to the checkbox (via x:Name or x:Key maybe) from outside of the ControlTemplate definition, then setting the Visibility would be trivial.

  3. Specify some kind of binding on the Visibilty in the ControlTemplate, something like:

    <Checkbox Visibility={Binding someNewPropertyOfTheTemplate}/>
    (Is this what TemplateBinding is used for?)

Are any of these ideas valid? And if so, which is the most appropriate? (If not – what is the correct way?)

I’m using VS2010 with .Net 4.0.

  • 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-05-27T06:44:51+00:00Added an answer on May 27, 2026 at 6:44 am

    I would go for #3. But your code is not quite correct. If you want to bind to properties of the actual control, on which template is being applied, you should use TemplateBinding. Suppose you have a custom control with a property ShowCheckboxes. Then in your template you should use

    <Checkbox Visibility={TemplateBinding ShowCheckboxes, 
                          Converter={StaticResource BooleanToVisibilityConverter}}/>
    

    Note, you may have to reference or create appropriate converter.
    On the other side, if you use MVVM, you may define your control property on the viewmodel class. Then you should use {Binding}.

    Also, there is another way to control which templates are applied.
    You may extract the template for your subcontrol out of the big template. And copy it, so you have two templates, that differ in the way you need.
    Then, in the main template you can set TemplateSelector for your subcontrol to the custom class, that you will implement. Look at the http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx for more examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very large files (more than 10Gb). I need only some lines from
We have some very large data files (5 gig to 1TB) where we need
I have a very large file that looks like this (see below). I have
I have a very large C project with many separate C files and headers
I have a very large app, 1.5 million lines of C++, which is currently
I have two very large files we'll call Old and New. New contains many
I need help with regular expression. I have very large collection of text files
I have very large dataframe and I need to choose variable number satisfying certain
I have 2 very large arrays (of size ~2,500,000). I need to find difference
I have a very large CSV file and I need to write an app

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.