Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
How to specify an empty string as Target null value in xaml

From here https://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue(v=vs.110).aspx,

It gives an example of specifying 'TargetNullValue':

<TextBox Width="150"
         Text="{Binding Source={StaticResource object2}, 
  Path=PropertyB, BindingGroupName=bindingGroup, 
  TargetNullValue=please enter a string}" />

My question is how can I specify an empty string for TargetNullValue?

I have tried "TargetNullValue= }" (there is a space between = and }, but that does not work, the target null value is null, instead of an empty string.

Thank you.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use x:Static in the xaml and define the string.empty there.

<TextBox Width="150"
         Text="{Binding Source={StaticResource object2}, 
  Path=PropertyB, BindingGroupName=bindingGroup, 
  TargetNullValue={x:Static system:String.Empty} }" />

You'll need to add the appropriate namespace to the xaml as needed. VS should do this for you though. Namespace required is

xmlns:system="clr-namespace:System;assembly=mscorlib"
over 4 years ago · Santiago Trujillo Report

0

I don't know why the answer saying to use '' is deleted, but it works fine for me:

<TextBox Text="{Binding NumberOfCats, TargetNullValue=''}" />
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!