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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:06:33+00:00 2026-06-13T21:06:33+00:00

I am trying to create a custom WPF control that has multiple UI elements

  • 0

I am trying to create a custom WPF control that has multiple UI elements to be displayed in different situations at different times, so they cannot be sensibly created in the same visual tree. I created dependency properties for each element, of type UIElement. This worked well.

When it came to styling control, it didn’t work so well. Although I can define a style for the control that sets my custom properties, the style is only instantiated once. So if multiple instances of my custom control use the same style, only the last one to be defined gets the visual tree. I understand that this is because the style sets the UIElement directly rather than using a template, and it is the template infrastructure that makes multiple instances of the tree defined within it (see https://stackoverflow.com/a/8702180/1453269)

My question is, how can I define a control that takes multiple templates in such a way that they will be applied? I have tried creating dependency objects of type DataTemplate. If I use a ContentPresenter to display the template, it just displays the type name of DataTemplate as text. I want it to apply the template values to my first dependency properties in a manner consistent with the rest of WPF. I had assumed there is a way to leverage the templating infrastructure in WPF, but I can’t find how to do that.

  • 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-13T21:06:33+00:00Added an answer on June 13, 2026 at 9:06 pm

    The key is the LoadContent method on FrameworkTemplate (from which DataTemplate derives). This method creates a copy of the template’s content.

    So to implement multiple templates, I created a Content and a Template pair of dependency properties for each templated UI property that I wanted. I registered for change notifications on the XXXTemplate dependency properties. The event handlers called into a method that set the matching XXXContent dependency property to the return value of LoadContent called on the new template value.

    In my control template for the containing object, I could then use a ContentPresenter bound to the XXXContent property of the desired UIElement.

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

Sidebar

Related Questions

I am trying to create a custom wpf control, I'm wondering how I can
I'm trying to create a custom file upload control in WPF 4.0 and I'm
I'm trying to create a GUI (WPF) Library where each (custom) control basically wraps
I am trying to create a custom user control in WPF. I want to
I have a custom WPF user control called a TimeoutPanel that I am trying
I'm trying to create a custom control in WPF to display the game tree
I'm trying to create a custom WPF control and place it inside of a
I'm trying to create a custom control that can be shared by both Silverlight
I'm trying to create a custom control with C#/WPF. See below for the XAML
I'm trying to create a custom TabItem that is dynamically added to a TabControl

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.