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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:58:48+00:00 2026-05-15T06:58:48+00:00

I have a problem with a databinding in WPF. When I try to use

  • 0

I have a problem with a databinding in WPF.

When I try to use a value converter and set the NotifyOnTargetUpdated=True property to True, I get an XamlParseException with the following message:

‘System.Windows.Data.BindingExpression’
value cannot be assigned to property
‘Contenu’ of object
‘View.UserControls.ShadowedText’.
Value cannot be null. Parameter name:
textToFormat Error at object
‘System.Windows.Data.Binding’ in
markup file
‘View.UserControls;component/saletotal.xaml’
Line 363 Position 95.

The binding is pretty standard:

<my:ShadowedText Contenu="{Binding Path=Total,
                                   Converter={StaticResource CurrencyToStringConverter},
                                   NotifyOnTargetUpdated=True}"
                 TargetUpdated="MontantTotal_TargetUpdated">
</my:ShadowedText>

(Styling properties removed for conciseness)

The converter exists in the resources and works correctly when NotifyOnTargetUpdated=True is removed. Similarly, the TargetUpdated event is called and implemented correctly, and works when the converter is removed.

Note: This binding is defined in a ControlTemplate, though I don’t think that is relevant to the problem.

Can anybody explain me what is happening ? Am I defining the binding wrong ? Are those features mutually exclusive (and in this case, can you explain why it is so) ?

Thanks in advance.

More info: Here is the content of the TargetUpdated handler:

private void MontantTotal_TargetUpdated(object sender, DataTransferEventArgs e)
{
    ShadowedText textBlock = (ShadowedText)e.TargetObject;
    double textSize = textBlock.Taille;
    double delta = 5;
    double defaultTaille = 56;
    double maxWidth = textBlock.MaxWidth;
    while (true)
    {
        FormattedText newFormat = new FormattedText(textBlock.Contenu,
                                                    CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                    new Typeface("Calibri"), textSize,
                                                    (SolidColorBrush) Resources["RougeVif"]);
        if (newFormat.Width < textBlock.MaxWidth && textSize <= defaultTaille)
        {
            if ((Math.Round(newFormat.Width) + delta) >= maxWidth || textSize == defaultTaille)
            {
                break;
            }
            textSize++;
        }
        else
        {
            if ((Math.Round(newFormat.Width) - delta) <= maxWidth && textSize <= defaultTaille)
            {
                break;
            }
            textSize--;
        }
    }

    textBlock.Taille = textSize;
}

The role of the handler is to resize the control based on the length of the content. It is quite ugly but I want to have the functional part working before refactoring.

  • 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-15T06:58:48+00:00Added an answer on May 15, 2026 at 6:58 am

    If you’re getting a XamlParseException that means this error is happening during the initialization of this control.

    With NotifyOnTargetUpdated=True specified, the TargetUpdated event is being raised inside your InitializeComponent call. At this point, it’s incredibly doubtful you have a DataContext, so the binding will evaluate to null. Normally, there’s no problem, but you are requesting an event be raised when the property is updated.

    So it’s hitting your event handler with a null textBlock.Contenu value, you’re passing it into the first parameter of FormattedText (which is named textToFormat) and it is throwing an ArgumentNullException.

    Practice some defensive programming and check your textBlock.Contenu value for null before running your code.

    Two tips for future reference:

    1) When receiving an exception, paste the entire stack trace, including InnerException (so call Exception.ToString). More often than not, you will see where it’s happening. If not, someone on here will see where it’s happening much quicker than you got your answer.

    2) When receiving an exception, and you don’t know where it’s being thrown from (and you clearly don’t, or you’d have seen it’s in your code), force Visual Studio to break on all exceptions.
    http://msdn.microsoft.com/en-us/library/d14azbfh(VS.80).aspx

    (Note that depending on your settings, the menu item they reference may or may not be there. You can also use CTRL+ALT+E to open the Exceptions dialog.)

    With this set, the debugger will stop on the exact line of code throwing the Exception.

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

Sidebar

Ask A Question

Stats

  • Questions 439k
  • Answers 439k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your problem is in the middle: || That means: OR… May 15, 2026 at 4:56 pm
  • Editorial Team
    Editorial Team added an answer You're never closing the StreamWriter... so I suspect it's not… May 15, 2026 at 4:56 pm
  • Editorial Team
    Editorial Team added an answer You want: for (i = 0; i < strlen(source); i++)… May 15, 2026 at 4:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.