Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda