How to display blank in WPF DoubleTextbox if databound value is null ?
To display a null value instead of the constant zero when the databound value of the editor is null, set the UseNullOption property as True.
UseNullOption
The UseNullOption is a boolean property of the Editors like CurrencyTextBox, IntegerTextBox, DoubleTextBox, PercentTextBox that is used to display a null when the databound value is null according to its Values such as True and False.
When the value of UseNullOption is True, it displays a Null Value when the databound Value of the editors is null.
When the value of UseNullOption is False, it disables the Null value and display the constant zero for the control.
Here is an example that describes the use of WPF Double Textbox.
The following code example demonstrates the same.
XAML
//Code used to explain how to set the UseNulloption true for an IntegerTextBox <Window x:Class="IntegerTextBox_127799.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion="http://schemas.syncfusion.com/wpf" Title="MainWindow" Height="350" Width="525"> <Grid> <syncfusion:IntegerTextBox Name="integer1" UseNullOption="True" Value="{Binding MyValue}" Height="50" /> </Grid> </Window>
C#
//Code explains about the property of the Binding value named MyValue namespace IntegerTextBox_127799 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private int? myVar; public int? MyValue { get { return myVar; } set { myVar = value; } } public MainWindow() { InitializeComponent(); this.DataContext = this; MyValue = null; } } }
The following screenshot displays the Null value when the UseNullOption property is set to True for an IntegerTextBox
Figure 1: Null value of the IntegerTextBox
XAML
//Code used to explain how to set the UseNulloption false for an IntegerTextBox <Window x:Class="IntegerTextBox_127799.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion="http://schemas.syncfusion.com/wpf" Title="MainWindow" Height="350" Width="525"> <Grid> <syncfusion:IntegerTextBox Name="integer1" UseNullOption="False" Value="{Binding MyValue}" Height="50" /> </Grid> </Window>
C#
//Code explains about the property of the Binding value named MyValue using Syncfusion.Windows.Shared; namespace IntegerTextBox_127799 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private int? myVar; public int? MyValue { get { return myVar; } set { myVar = value; } } public MainWindow() { InitializeComponent(); this.DataContext = this; MyValue = null; } } }
The following screenshot displays the default value of the IntegerTextBox as Zero when the UseNullOption property is set to False for an IntegerTextBox.
Figure 2: Default value of the IntegerTextBox as Zero
Conclusion
I hope you enjoyed learning
about how
to display a blank in the editors when the databound value is null.
You can refer to our WPF Double Textbox feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Double Textbox example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!