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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:23:37+00:00 2026-06-11T14:23:37+00:00

The example given here is a simplification of the actual UserControl that I am

  • 0

The example given here is a simplification of the actual UserControl that I am trying to implement but it illustrates the structure and suffers from the same problem. The user control has a DependencyProperty Words that sets the text of textblock that is defined in the user control XAML.

    public partial class MyControl : UserControl
    {
        public static readonly DependencyProperty WordsProperty = DependencyProperty.Register("Words", typeof(string), typeof(MyControl));
        public MyControl()
        {
            InitializeComponent();
        }
        public string Words
        {
            get { return (string)GetValue(WordsProperty); }
            set
            {
                m_TextBlock.Text = value;
                SetValue(WordsProperty, value);
            }

An INotifyPropertyChanged ViewModelBase class derived ViewModel is assigned to the mainWindow DataContext. The ModelText property set calls OnPropertyChanged.

class MainWindow : ViewModelBase
{
    private string m_ModelString;
    public string ModelText
    {
        get { return m_ModelString; }
        set
        {
            m_ModelString = value;
            base.OnPropertyChanged("ModelText");
        }
    }
}

In the MainWindow XAML binding is made to the UserControl and a TextBlock

 <Window x:Class="Binding.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="218" Width="266" xmlns:my="clr-namespace:Binding.View">
    <Grid>
        <my:MyControl Words="{Binding ModelText}" HorizontalAlignment="Left" Margin="39,29,0,0" x:Name="myControl1" VerticalAlignment="Top" Height="69" Width="179" Background="#FF96FF96" />
        <TextBlock Height="21" HorizontalAlignment="Left" Margin="59,116,0,0" Name="textBlock1" Text="{Binding ModelText}" VerticalAlignment="Top" Width="104" Background="Yellow" />
    </Grid>
</Window>

The binding works for the textblock but not for the user control. Why can’t UserControl DependencyProperty be bound in the same way as Control Properties?

  • 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-11T14:23:38+00:00Added an answer on June 11, 2026 at 2:23 pm

    The culprit is:

    m_TextBlock.Text = value;
    

    WPF does not directly use properties backed by a DP.

    If you want to update m_TextBlock.Text when the WordsProperty is modified, either bind that textblock to Words, or use the PropertyChangedCallback in UIPropertyMetadata:

     public static readonly DependencyProperty WordsProperty = 
             DependencyProperty.Register("Words", 
                                        typeof(string), 
                                        typeof(MyControl),
                                        new UIPRopertyMetadata(
                     new PropertyChangedCallback(
                         (dpo, dpce) => 
                         {
                             //Probably going to need to first cast dpo to MyControl
                             //And then assign its m_TextBlock property's text.
                             m_TextBlock.Text = dpce.NewValue as string;
                         })));
    

    Consider dpo the sender, and dpce the event args.

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

Sidebar

Related Questions

Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
For example, my goal is to test the code given here: PHP script that
I am trying to extend the JSON.net example given here http://james.newtonking.com/projects/json/help/CustomCreationConverter.html I have another
Note that I'm mirroring the example given here very closely. In fact, my situation
I am trying to run the EasyMock example given here with TestNG and am
I'm trying to run the sample tiles example given here . Below is my
Trying to run the Blocking Queue example given here . Using the .NET Queue
At the moment I'm trying to run the example given here http://jqueryui.com/demos/animate/#demo If I
I've been trying to adjust the example of uisng RegNotifyChangeKeyValue() given here for my
I am trying to do work with examples on Trees as given here: http://cslibrary.stanford.edu/110/BinaryTrees.html

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.