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

  • Home
  • SEARCH
  • 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 421035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:56:38+00:00 2026-05-12T18:56:38+00:00

I am creating a custom control. I want the template for this control to

  • 0

I am creating a custom control.

I want the template for this control to use different controls for the root control based on the value of a dependency property called CanExpand. CanExpand is defined in the custom control class.

If CanExpand is true, I want to display using an Expander:

<ControlTemplate ...>
   <Expander ...>
      <!--...-->
      <ContentPresenter/>
   </Expander>
</ControlTemplate>

If CanExpand is false, I want to display using a HeaderedContentControl instead:

<ControlTemplate ...>
   <HeaderedContentControl ...>
      <!--...-->
      <ContentPresenter/>
   </HeaderedContentControl>
</ControlTemplate>

I thought of using a DataTemplateSelector, but this is a ControlTemplate not a DataTemplate and there is no selector property for the Template of a control.

I can’t set the different controls to visible/hidden with a Trigger because the child content can only live under one control. Also, I don’t think you can change the Content property using a Trigger.

Any suggestions?

Thanks.

  • 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-12T18:56:38+00:00Added an answer on May 12, 2026 at 6:56 pm

    Inside your Style, set the ControlTemplate property for the default state and then have a Trigger which sets the ControlTemplate property to a different template. For example:

    <Style ...>
        <Setter Property="ControlTemplate">
            <ControlTemplate ...>    
            </ControlTemplate>
        </Setter>
        <Style.Triggers>
            <Trigger Property="YourProperty" Value="WhateverValue">
                <Setter Property="ControlTemplate">
                    <ControlTemplate ...>
                    </ControlTemplate>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    

    Keep in mind you can have a trigger on the same property for multiple values, each value getting a completely different template.

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

Sidebar

Related Questions

I need a help about creating custom wpf controls.I want to create a template
I'm creating a custom control with a property that can take value from a
I am creating an ASP.NET custom control. I want to set the body onload
I'm creating a custom control and I want to have style templates that can
I'm creating a custom control called FooControl derived from ItemsControl have a default style
I am creating a custom control and i want to add some properties in
I'm creating a custom edit control for my content authors to use in the
Im currently creating a custom control (based on the WPF DataGrid). What i would
I'm an creating a custom user control for .NET Compact Framework and I want
I am creating a custom control(deriving from Control ) and want to define 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.