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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:53:17+00:00 2026-05-14T08:53:17+00:00

I have a parent contentcontrol which displays data via a datatemplate. The datatemplate contains

  • 0

I have a parent contentcontrol which displays data via a datatemplate. The datatemplate contains a stackpanel with several usercontols of the same type. I like to set the property only once on the parent control, it must set the value of the property on all the subcontrols. But if there is a way to do it on the stackpanel it’s also OK. The template can be changed at runtime and the values need also to be propagated to the new template.

My current solution is to implement the property on both parent and subcontrol and use code to propagate the value from the parent to all the subcontrols. My question is: is there a better or other ways of doing this?

EDIT:
Some notes of clarification to my question. The application is currently WPF, but if it’s portable to silverlight it would be a bonus. The property is a dependency of the type Style.

I want to use it to style part of the subcontrol. Currently the datatemplate is stored in a separate resource dictionary, so it can be reused. The visuals of the subcontrol are styled via controltemplate. The template contains three different controls, the first one is a label. The need (desire, foolish wish) is to set the style only once, to give the label on all the subcontrols in the datatemplate a consistent look and feel.
So the crux of the problem is to override the value of the a style dependency property on a subcontrol, stored in a resource dictionary from a container control. Both are custom user controls, so all options are open.

<Parent SubSubStyle="x" Template="template" />

<DataTemplate x:Key=template>
  <StackPanel>
    <Subcontrol SubSubStyle="?"/>
    <Subcontrol SubSubStyle="?"/>
    <Subcontrol SubSubStyle="?"/>
    <Subcontrol SubSubStyle="?"/>
  </StackPanel>
</DataTemplate>
  • 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-14T08:53:18+00:00Added an answer on May 14, 2026 at 8:53 am

    Is the property that you’re trying to set a DependencyProperty that you have created? If so, the ideal thing to do in WPF is to define the property such that it will be inherited by elements in the visual tree.

    If it’s not your own dependency property (or if you’re using Silverlight which does not support this mechanism) then you should instead use implicit styles.

    public class MyControl {
    
        // be prepared for some dependency property hell below
        // this defines a DependencyProperty whose value will be inherited
        // by child elements in the visual tree that do not override
        // the value. An example of such a property is the FontFamily
        // property. You can set it on a parent element and it will be
        // inherited by child elements that do not override it.
    
        public static readonly DependencyProperty MyInheritedProperty =
            DependencyProperty.Register(
                "MyInherited",
                typeof(string),
                typeof(MyControl),
                new FrameworkPropertyMetadata(
                    null,
                    FrameworkPropertyMetadataOptions.Inherits
                )
            );
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent class which contains a child object. I am using set
I have parent child data in excel which gets loaded into a 3rd party
I have parent project parent, which has three modules like: <groupId>com.dummy.bla.bla</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging>
I have parent/child relationship set up via Node Reference. A Child record can have
I have a parent object which has a one to many relationship with an
I have a parent thread (non-UI) which creates some child threads to do some
I have parent class c1 with function hi(). class c2 extends c1 and contains
I have Parent page and a Child page('empW.cfm'),which is nothing but a popup window
I have parent pom which configures certain plugins <pluginManagement> </plugins> <plugin> <artifactId>gmaven-plugin</artifactId> ... </plugin>
I have parent form and child form. Parent form contains a dataGridView (list of

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.