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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:01:08+00:00 2026-05-21T04:01:08+00:00

I have been trying to understand and get something working with dependency properties. I

  • 0

I have been trying to understand and get something working with dependency properties.

I have read loads of descriptions and explanations about DP’s, and I also think I understand where they should be used.

I have read this and the links / references contain therein.

However, im still having problems. These maybe just mental blockages, maybe im clinging onto some idea or belief that i cant let go of.. anyway..

What im trying to do is create a control with a DP on it.
Use that control in xaml and bind to the DP.

When i specify a value for the DP in the xaml the value is diaplayed on the user control as expected.

<DpTestProj:UserControl1 MyName="Steve"

However when i try to bind to it the value is not set, and i get

System.Windows.Data Error: 40 : BindingExpression path error: ‘PersonName’ property not found on ‘object’ ”UserControl1′ (Name=”)’. BindingExpression:Path=PersonName; DataItem=’UserControl1′ (Name=”); target element is ‘UserControl1’ (Name=”); target property is ‘MyName’ (type ‘String’)

Which suggests i have done something wrong with the binding or datacontext somewhere.
But i cant see what.

My code is as follows.

UserControl1 has the following DP

public const string MyNamePropertyName = "MyName";
public string MyName
{
    get
    {
        return (string)GetValue(MyNameProperty);
    }
    set
    {
        SetValue(MyNameProperty, value);
    }
}

public static readonly DependencyProperty MyNameProperty = DependencyProperty.Register(
    MyNamePropertyName,
    typeof(string),
    typeof(UserControl1),
    new UIPropertyMetadata("No Name"));

Its used on the MainWindow like this

<StackPanel x:Name="LayoutRoot">
    <DpTestProj:UserControl1 MyName="{Binding PersonName}" MyList="{Binding SomeListItems}" />
</StackPanel>

I’m using MVVM Light si the data context of the MainWindow is

DataContext="{Binding Main, Source={StaticResource Locator}}">

PersonName is a normal CLR (string) property that lives on the MainViewModel

If its easier I have posted the entire solution here

  • 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-21T04:01:09+00:00Added an answer on May 21, 2026 at 4:01 am

    And the answer is…

    you cant bind to the clr wrapper of a dp directly with a vanilla binding (even if you have set the dataContext of the userControl as this (i.e. the code behind of the userControl))

    You can do one of two things to get changes to the dependency property reflected in the UI elements.

    1) Use a RelativeSource Binding in FindAncestor mode

    {Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=DpWrapperProp}"
    

    2) Use the Dp’s callback to update your UI element. (If youre using the callback to do some validation anyway, then this might be the route for you).
    Because the Callback is Static you need to create a non static method to do the update, and call that from the static method. The ui element (label textBlock whatever) also need to be named.

        private static void ChangeText(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as MyUserControl).UpdateText(e.NewValue.ToString());
        }
    
        private void UpdateText(string newText)
        {
            MyLabel.Content = newText; //set the content of the named label 
                                       //defined in the userControl XAML
        }
    

    *the above examples are generic and not nesecarily related to my original code.

    fyi i arrived at these solutons with the help of this and this

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

Sidebar

Related Questions

I have been trying to understand the way ActionScript's events are implemented, but I'm
okay i have been trying to understand this for hours i am learning VB
So, I have been trying to understand Socket.io lately, but I am not a
I've been trying to get a handle on Dialogs. I read the android dev
(post updated for working code) I've been trying to get my android app to
I understand there are many threads like mine but I have been trying to
I have been trying to understand what should be the right way in using
I have been trying to get a good grasp of Azure Table storage for
In an effort to learn more about php and mysql, I have been working
I have been trying to understand why I am getting an exception when trying

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.