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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:21:33+00:00 2026-05-24T09:21:33+00:00

As the title already says I am having trouble using databinding with a DependencyProperty.

  • 0

As the title already says I am having trouble using databinding with a DependencyProperty. I have a class called HTMLBox:

public class HTMLBox : RichTextBox
{
    public static readonly DependencyProperty TextProperty = 
    DependencyProperty.Register("Text", typeof(string), typeof(HTMLBox));

    public string Text
    {
        get
        {
            return GetValue(TextProperty) as string;
        }
        set
        {
            Console.WriteLine("Setter...");
            SetValue(TextProperty, value);
        }
    }

    public HTMLBox()
    {
        // Create a FlowDocument
        FlowDocument mcFlowDoc = new FlowDocument();

        // Create a paragraph with text
        Paragraph para = new Paragraph();
        para.Inlines.Add(new Bold(new Run(Text)));

        // Add the paragraph to blocks of paragraph
        mcFlowDoc.Blocks.Add(para);

        this.Document = mcFlowDoc;
    }
}

I reading the Text-property in the Constructor, so it should be displayed as text when a string is bound to the property. But even though I bind some data to the Text property in xaml, I don’t even see the “Setter…”-Message which should be shown when the Text-property is set.

    <local:HTMLBox Text="{Binding Text}" 
           Width="{Binding Width}"  
           AcceptsReturn="True" 
           Height="{Binding Height}" />

If I change HTMLBox to TextBox the text is displayed properly, so the mistake is probably somwhere in my HTMLBox class. What am I doing wrong?

  • 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-24T09:21:34+00:00Added an answer on May 24, 2026 at 9:21 am

    You have a few issues going on here:

    1. You should not place logic in the set / get of your CLR property which wraps your dependency property. This property is only there to provide a more convenient mechanism for getting / setting your dependency property. There is no guarantee that the XAML parser will invoke this setter. If you need to invoke any logic when your dependency property is changed, do this via a change event handler when you register your dependency property via DependencyProperty.Register.
    2. You build your control’s UI in the constructor, you have timing issue here! To construct an instance of your class the constructor is first called, then the various properties are set. Text will always be the default value in the constructor. Again, a similar solution to (1), when your Text property changes, rebuild / update your UI.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have my models set up already. class books(models.Model): title = models.CharField... ISBN
As title says, mock code to demostrate my problem Driver Class import java.io.*; public
as already the title of my question says I have the problem that the
As the title already says, I'd like to know how to create a 1024x1024
As the title already says, I would like to know if it is somehow
as the title already says, I need to convert an int[] to a ByteBuffer
Well, my problem is what the title says. I have build a small application
I believe the title already says it all, but here is my question: what
The title pretty much says it all. If I have nargs greater than 1,
The title pretty much says it already. I've looked through the AMD website and

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.