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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:04:16+00:00 2026-05-25T01:04:16+00:00

My question concerns Silverlight (but I guess WPF as well). Basically I know, how

  • 0

My question concerns Silverlight (but I guess WPF as well).

Basically I know, how to create dependency property in a user control and how to make it work. But what i was trying to do, and didn’t succeded is: to create dependency property (or more than one) in a class, and this class will become a dependency property for my user control.

With other words:

// my UserControl
public class DPTest : UserControl
{
    // dependency property, which type is a class, and this class will be holding other dependency properties        
    public static readonly DependencyProperty GroupProperty =
        DependencyProperty.Register("Group", typeof(DPGroup), typeof(DPTest), new PropertyMetadata(new DPGroup(), OnPropertyChanged));

    public DPGroup Group
    {
        get { return (DPGroup)GetValue(GroupProperty); }
        set { SetValue(GroupProperty, value); }
    }    

    // this occurs only when property Group will change, but not when a member of property Group will change        
    static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        DPTest g = d as DPTest;
        // etc.     
    }
}

// a class, where I want to hold my dependency properties
public class DPGroup : DependencyObject
{

    public static readonly DependencyProperty MyProperty1Property =
        DependencyProperty.RegisterAttached("MyProperty1", typeof(int), typeof(DPGroup), new PropertyMetadata(1, OnPropertyChanged));

    public int MyProperty1
    {
        get { return (int)GetValue(MyProperty1Property); }
        set { SetValue(MyProperty1Property, value); }
    }

    // I would like to notify "the parent" (which means user control "DPTest" ), that member MyProperty1 has changed
    static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        DPTest g = d as DPTest;
        if (g != null) g.textBox1.Text = g.Group.MyProperty1.ToString();
    }
}

What I want to achieve is to notify (in design time in XAML) a user control DPTest, that member of Group property (Group.MyProperty1) changed it’s value. I managed to make it happen in a run-time, for example by using event handler defined in DPGroup class, but this doesn’t work in design-time in xaml.

<Grid x:Name="LayoutRoot" Background="White">
    <local:DPTest>
        <local:DPTest.Group>
            <local:DPGroup MyProperty1="2"/>
        </local:DPTest.Group>
    </local:DPTest>
</Grid>

It works, but only first time, during creating tag:

 <local:DPGroup MyProperty1="2"/>

and after this, changing value of MyProperty1, does not fire DPTest.OnPropertyChange. Probably fires DBGroup.OnPropertyChanged, but this of course does not notify user control DPTest about it. So how to make DPTest know, that the Group.MyProperty1 has changed?

I don’t want to make any bindings from MyProperty1 to respective property created inside user control DPTest (not to duplicate properties), the point is to have a group of properties in separate class, so i can use this group more than once, like:

// my UserControl
public class DPTest : UserControl
{
    public DPGroup Group1 { ... } 
    public DPGroup Group2 { ... } 
}

I see some analogy to UIElement.RenderTransform (let’s say it is my Group property) which holds for example ScaleTransform

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RenderTransform>
        <ScaleTransform ScaleX="0.4"/>
    </Grid.RenderTransform>      
</Grid>

ScaleX is an analogy to MyProperty1. The difference is, that changing value of ScaleX (in XAML) will reflect immediate changes in design-time, and exactly this I am trying to achieve.

I was trying to find a solution in entire google/stack overflow and others, but none found. Everywhere are just examples of creating dependency properties inside a user control.

Thank you for your time.
Any help much appreciated.

edit: based on Harlow Burgess answer, a managed to make a working example in Silverlight. I put the whole solution below as an separate answer.

  • 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-25T01:04:16+00:00Added an answer on May 25, 2026 at 1:04 am

    From: http://msdn.microsoft.com/en-us/library/ms752914.aspx#setting_properties_data_binding

    Dependency properties, or the DependencyObject class, do not natively
    support INotifyPropertyChanged
    for purposes of producing notifications
    of changes in DependencyObject source property value for data binding
    operations. For more information on how to create properties for use
    in data binding that can report changes to a data binding target, see
    Data Binding Overview.

    It would be inefficient to design a system that notifies an entire object graph anytime any property of any subproperty (of any subproperty, of any subproperty, …) changes. So instead you should use Data Binding to specific properties when you need to do something when that property changes, or if you really want to be notified when any subproperty changes, you should implement INotifyPropertyChanged.

    How to: Implement Property Change Notification

    Example:

    public class DPGroup : DependencyObject, INotifyPropertyChanged 
    {      
        public static readonly DependencyProperty MyProperty1Property =
            DependencyProperty.RegisterAttached(
            "MyProperty1",
            typeof(int),
            typeof(DPGroup),
            new PropertyMetadata(1));
    
        public int MyProperty1
        {        
            get { return (int)GetValue(MyProperty1Property); }        
            set { SetValue(MyProperty1Property, value); }
        } 
    
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            NotifyPropertyChanged(e.Property.Name);
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    public class DPTest : UserControl   
    {     
        public static readonly DependencyProperty GroupProperty =         
            DependencyProperty.Register(
            "Group",
            typeof(DPGroup),
            typeof(DPTest),
            new PropertyMetadata(
                new DPGroup(),
                new PropertyChangedCallback(OnGroupPropertyChanged)
                )
            );
    
        public DPGroup Group     
        {
            get { return (DPGroup)GetValue(GroupProperty); }
            set { SetValue(GroupProperty, value);}     
        }
    
        static void OnGroupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DPTest control = (DPTest)d;
    
            DPGroup oldGroup = e.OldValue as DPGroup;
            if (oldGroup != null)
            {
                oldGroup.PropertyChanged -=new PropertyChangedEventHandler(control.group_PropertyChanged);
            }
    
            DPGroup newGroup = e.NewValue as DPGroup;
            if (newGroup != null)
            {
                newGroup.PropertyChanged +=new PropertyChangedEventHandler(control.group_PropertyChanged);
            }
    
            control.UpdateTextBox();
        }
    
        private void group_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.UpdateTextBox();
        }
    
        private void UpdateTextBox()
        {
            this.textBox1.Text = this.Group.MyProperty1.ToString(); 
        }
    
        private TextBox textBox1;
    
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question concerns c# and how to access Static members ... Well I don't
I am using Sqlite3 with Flask microframework, but this question concerns only the Sqlite
This question concerns generics and types as well as datatables. The following snippet is
(The following question concerns the OCaml language and has examples in OCaml, but the
My question concerns the android development. I would like to know if the method
This question concerns Postgresql 8.3. I cannot yet create tags so Ichose version 8.4
My question concerns Google Web Toolkit (GWT). I'm about to begin development for a
My question concerns markup that surrounds some of the default phone number labels in
In fact, my question concerns an algorithm. I need to be able to attach
Another slightly non-technical question, but I couldn't decide whether to ask here or on

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.