Set value to null in WPF binding

I am using .NET 3.5 SP1 so it’s very simple: <TextBox Text=”{Binding Price, TargetNullValue=””}”/> Which stands for (thanks Gregor for your comment): <TextBox Text=”{Binding Price, TargetNullValue={x:Static sys:String.Empty}}”/> sys is the imported xml namespace for System in mscorlib: xmlns:sys=”clr-namespace:System;assembly=mscorlib” Hope that helped.

What is the default value of the nullable type “int?” (including question mark)?

The default value for int? — and for any nullable type that uses the “type?” declaration — is null. Why this is the case: int? is syntactic sugar for the type Nullable<T> (where T is int), a struct. (reference) The Nullable<T> type has a bool HasValue member, which when false, makes the Nullable<T> instance “act … Read more

Are nullable types reference types?

No, a nullable is a struct. What is happening is that the nullable struct has two values: The value of the data type (int for int?, DateTime for DateTime?, etc.). A boolean value which tells if the data type value has been set. (HasValue is the property.) When you set the value of the data … Read more

Nullable ToString()

You are quite correct. Also in this question, the former solution is suggested while nobody actually notices ToString() already gives the correct answer. Maybe the argument for the more verbose solution is readability: When you call ToString() on something that is supposed to be null, you usually expect a NullReferenceException, although here it isn’t thrown.

Can’t find @Nullable inside javax.annotation.*

You need to include a jar that this class exists in. You can find it here If using Maven, you can add the following dependency declaration: <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>3.0.2</version> </dependency> and for Gradle: dependencies { testImplementation ‘com.google.code.findbugs:jsr305:3.0.2’ }