Skip to content

Commit 0f30cd7

Browse files
authored
Update README.md
1 parent 5fd33e0 commit 0f30cd7

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
1-
# How-to-set-null-value-in-WPF-DateTimeEdit
2-
This repository provides a detailed example of how to set a **null value** in the **WPF DateTimeEdit** control, which is part of the Syncfusion WPF suite. By default, the DateTimeEdit control requires a valid date and time value, but in many real-world scenarios, you may want to allow users to clear the value or represent an empty state. This is especially useful in forms where the date field is optional or when you need to reset the control programmatically.
1+
# How to Set Null Value in WPF DateTimeEdit
2+
This example demonstrates how to allow null values in the Syncfusion WPF DateTimeEdit control. By default, DateTimeEdit requires a valid date and time value, but in many real-world scenarios, you may want to allow users to clear the value or represent an empty state. This is especially useful in forms where the date field is optional or when you need to reset the control programmatically.
33

4-
The sample demonstrates how to configure the DateTimeEdit control to accept null values by customizing its properties and handling specific events. This approach ensures that the control behaves consistently when the user clears the input or when the application logic sets the value to null. You will learn how to set the value to null, and ensure proper UI updates without breaking the control’s functionality.
4+
## Why This Is Useful
5+
- **Optional Fields**: Ideal for forms where date selection is not mandatory.
6+
- **Reset Functionality**: Allows clearing the date programmatically.
7+
- **Better UX**: Displays custom text when no date is selected.
58

6-
This guide walks you through customizing the control behavior using event handlers and properties, making your WPF application more flexible and user-friendly.
9+
## Key Properties
10+
- **IsEmptyDateEnabled**: Enables empty date selection.
11+
- **NullValue**: Represents the null state.
12+
- **NoneDateText**: Custom text displayed when no date is selected.
13+
- **ShowMaskOnNullValue**: Controls whether the mask is shown when the value is null.
14+
15+
## Code Example
16+
**XAML**
17+
```XAML
18+
<syncfusion:DateTimeEdit x:Name="dateTimeEdit"
19+
Height="23"
20+
Width="150"
21+
IsEmptyDateEnabled="True"
22+
IsVisibleRepeatButton="True"
23+
NullValue="{x:Null}"
24+
NoneDateText="No date is selected"
25+
ShowMaskOnNullValue="False" />
26+
```
27+
28+
**C#**
29+
```C#
30+
DateTimeEdit dateTime = new DateTimeEdit
31+
{
32+
Height = 25,
33+
Width = 150,
34+
IsEmptyDateEnabled = true,
35+
IsVisibleRepeatButton = true,
36+
NullValue = null,
37+
NoneDateText = "No date is selected",
38+
ShowMaskOnNullValue = false
39+
};
40+
41+
this.Content = dateTime;
42+
```
43+
44+
## Output
45+
46+
![Null value in WPF DateTimeEdit](output.png)

0 commit comments

Comments
 (0)