syncfusion-wpf-datetimepicker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing DateTimeEdit (WPF)
实现DateTimeEdit(WPF)
An enhanced date-time input control with mask editing, calendar/clock dropdown, date range restriction, formatting, and MVVM binding support.
一款增强型日期时间输入控件,支持掩码编辑、日历/时钟下拉、日期范围限制、格式化以及MVVM绑定。
When to Use This Skill
何时使用本技能
Use this skill when the user needs to:
- Add a date/time picker input field to a WPF application
- Bind a selected date to a ViewModel property (two-way binding)
DateTime - Format the displayed date/time (predefined patterns or custom patterns)
- Restrict selectable dates with min/max range or blackout dates
- Enable inline editing (mask mode or free-form text editing)
- Show a calendar, clock, or combined dropdown picker
- Display watermark text when no date is selected
- Handle null date values
- Apply locale-specific date formats via
CultureInfo - Localize dropdown button labels (Today/None)
当用户需要以下功能时使用本技能:
- 为WPF应用添加日期/时间选择器输入字段
- 将选中的日期绑定到ViewModel属性(DateTime双向绑定)
- 格式化显示的日期/时间(预定义模式或自定义模式)
- 通过最小/最大范围或禁用日期限制可选日期
- 启用内联编辑(掩码模式或自由文本编辑)
- 显示日历、时钟或组合式下拉选择器
- 未选择日期时显示水印文本
- 处理空日期值
- 通过应用特定地区的日期格式
CultureInfo - 本地化下拉按钮标签(今日/无)
Component Overview
组件概述
| Class | Namespace | Assembly |
|---|---|---|
| | |
XAML Namespace:
xml
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"NuGet:
Install-Package Syncfusion.Shared.WPF| 类 | 命名空间 | 程序集 |
|---|---|---|
| | |
XAML命名空间:
xml
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"NuGet:
Install-Package Syncfusion.Shared.WPFDocumentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- Assembly setup and XAML namespace
- Add via designer, XAML, or C#
- Setting value
DateTime - Two-way MVVM binding with event
DateTimeChanged - Predefined quick reference
Pattern - /
MinDateTimebasicsMaxDateTime - SfSkinManager theme setup
📄 阅读: references/getting-started.md
- 程序集设置与XAML命名空间
- 通过设计器、XAML或C#添加控件
- 设置值
DateTime - 带事件的双向MVVM绑定
DateTimeChanged - 预定义快速参考
Pattern - /
MinDateTime基础用法MaxDateTime - SfSkinManager主题设置
DateTime Editing
DateTime编辑
📄 Read: references/datetime-editing.md
- Mask editing (default) — field-by-field input with auto-validation
- Keyboard navigation between date/time fields
- Free-form text editing ()
CanEdit="True" - Mouse wheel value change ()
EnableMouseWheelEdit - Up/down repeat buttons (,
IsVisibleRepeatButton)IsEnabledRepeatButton - Custom repeat button UI templates
- Alpha key month navigation ()
EnableAlphaKeyNavigation - BackSpace/Delete key editing
- and
OnFocusBehaviorfocus controlAutoForwarding
📄 阅读: references/datetime-editing.md
- 掩码编辑(默认)——逐字段输入并自动验证
- 日期/时间字段间的键盘导航
- 自由格式文本编辑()
CanEdit="True" - 鼠标滚轮更改值()
EnableMouseWheelEdit - 上下重复按钮(,
IsVisibleRepeatButton)IsEnabledRepeatButton - 自定义重复按钮UI模板
- 字母键月份导航()
EnableAlphaKeyNavigation - 退格/删除键编辑
- 与
OnFocusBehavior焦点控制AutoForwarding
Formatting & Culture
格式化与地区设置
📄 Read: references/formatting-and-culture.md
- All 11 predefined values
Pattern - with
CustomPatternPattern="CustomPattern" - with
DateTimeFormatDateTimeFormatInfo - for locale-specific formatting
CultureInfo - /
PatternChangedeventsCustomPatternChanged
📄 阅读: references/formatting-and-culture.md
- 全部11种预定义值
Pattern - 结合使用
Pattern="CustomPattern"CustomPattern - 结合使用
DateTimeFormatInfoDateTimeFormat - 用于特定地区格式化的
CultureInfo - /
PatternChanged事件CustomPatternChanged
Dropdown Popup
下拉弹出框
📄 Read: references/dropdown-popup.md
- : Calendar / Clock / Combined
DropDownView - Keyboard shortcuts (Alt+Down, F4)
- (Date vs DateTime)
TodayButtonAction - — None button / reset to null
IsEmptyDateEnabled - /
AbbreviatedMonthNamesShortestDayNames - ,
PopupDelayIsButtonPopUpEnabled - custom UI
DropDownButtonTemplate - Custom calendar and clock (SfDateSelector / SfTimeSelector)
- for clock
TimeStepInterval
📄 阅读: references/dropdown-popup.md
- :日历 / 时钟 / 组合视图
DropDownView - 键盘快捷键(Alt+Down, F4)
- (日期 vs 日期时间)
TodayButtonAction - ——无按钮 / 重置为空
IsEmptyDateEnabled - /
AbbreviatedMonthNamesShortestDayNames - ,
PopupDelayIsButtonPopUpEnabled - 自定义UI
DropDownButtonTemplate - 自定义日历和时钟(SfDateSelector / SfTimeSelector)
- 时钟的
TimeStepInterval
Date Restrictions & Null Values
日期限制与空值
📄 Read: references/date-restrictions.md
- /
MinDateTime— prevent out-of-range selectionMaxDateTime - — block specific date ranges
BlackoutDates - — month/year only
DisableDateSelection - — prevent all user edits
IsReadOnly - /
NullValue/IsEmptyDateEnabledShowMaskOnNullValue - watermark
NoneDateText
📄 阅读: references/date-restrictions.md
- /
MinDateTime——防止选择超出范围的日期MaxDateTime - ——阻止特定日期范围
BlackoutDates - ——仅选择月份/年份
DisableDateSelection - ——禁止所有用户编辑
IsReadOnly - /
NullValue/IsEmptyDateEnabledShowMaskOnNullValue - 水印
NoneDateText
Appearance
外观
📄 Read: references/appearance.md
- ,
Foreground,BackgroundSelectionBrush FocusedBorderBrush- RTL
FlowDirection - Repeat button background and margins
- SfSkinManager themes list
📄 阅读: references/appearance.md
- ,
Foreground,BackgroundSelectionBrush FocusedBorderBrush- RTL(从右到左)
FlowDirection - 重复按钮背景与边距
- SfSkinManager主题列表
Localization
本地化
📄 Read: references/localization.md
- setup
CurrentUICulture - Resource file naming:
Syncfusion.Shared.Wpf.{culture}.resx - Name/Value pairs for Today/None button labels
- French culture example
📄 阅读: references/localization.md
- 设置
CurrentUICulture - 资源文件命名:
Syncfusion.Shared.Wpf.{culture}.resx - 今日/无按钮标签的键值对
- 法语地区示例
Quick Start Example
快速入门示例
xml
<!-- MainWindow.xaml -->
<Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<syncfusion:DateTimeEdit DateTime="{Binding SelectedDate, Mode=TwoWay}"
Pattern="ShortDate"
MinDateTime="01/01/2020"
MaxDateTime="12/31/2030"
Height="25" Width="200"
Name="dateTimeEdit"/>
</StackPanel>
</Window>csharp
// ViewModel.cs
public class ViewModel : NotificationObject
{
private DateTime _selectedDate = DateTime.Now;
public DateTime SelectedDate
{
get => _selectedDate;
set { _selectedDate = value; RaisePropertyChanged(nameof(SelectedDate)); }
}
}xml
<!-- MainWindow.xaml -->
<Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<syncfusion:DateTimeEdit DateTime="{Binding SelectedDate, Mode=TwoWay}"
Pattern="ShortDate"
MinDateTime="01/01/2020"
MaxDateTime="12/31/2030"
Height="25" Width="200"
Name="dateTimeEdit"/>
</StackPanel>
</Window>csharp
// ViewModel.cs
public class ViewModel : NotificationObject
{
private DateTime _selectedDate = DateTime.Now;
public DateTime SelectedDate
{
get => _selectedDate;
set { _selectedDate = value; RaisePropertyChanged(nameof(SelectedDate)); }
}
}Common Patterns
常见场景
| Scenario | Properties / Approach |
|---|---|
| Two-way date binding | |
| Show calendar + clock | |
| Free-form text editing | |
| Date-only range restriction | |
| Allow null / clear value | |
| Watermark when null | Add |
| Custom date display | |
| Culture-aware formatting | |
| Read-only input | |
| RTL layout | |
| Apply theme | |
| 场景 | 属性 / 实现方式 |
|---|---|
| 双向日期绑定 | |
| 显示日历+时钟 | |
| 自由格式文本编辑 | |
| 仅日期范围限制 | |
| 允许空值/清除值 | |
| 空值时显示水印 | 结合空值属性添加 |
| 自定义日期显示 | |
| 地区感知格式化 | |
| 只读输入 | |
| RTL布局 | |
| 应用主题 | |
Key Properties
关键属性
| Property | Type | Default | Description |
|---|---|---|---|
| | | Selected date/time value |
| | | Display format pattern |
| | | Custom format string (requires |
| | System culture | Locale for date formatting |
| | | Enable free-form text editing |
| | | Minimum selectable date |
| | | Maximum selectable date |
| | | Popup content: Calendar/Clock/Combined |
| | | Allow null date value |
| | | Value when date is cleared |
| | | Watermark text when value is null |
| | | Show mask vs watermark when null |
| | | Prevent user edits |
| | | Show up/down spinner buttons |
| | | Allow mouse wheel to change value |
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | | 选中的日期/时间值 |
| | | 显示格式模式 |
| | | 自定义格式字符串(需设置 |
| | 系统地区 | 日期格式化的地区设置 |
| | | 启用自由格式文本编辑 |
| | | 最小可选日期 |
| | | 最大可选日期 |
| | | 弹出内容:日历/时钟/组合视图 |
| | | 允许空日期值 |
| | | 日期清除后的值 |
| | | 值为空时的水印文本 |
| | | 为空时显示掩码还是水印 |
| | | 禁止用户编辑 |
| | | 显示上下微调按钮 |
| | | 允许通过鼠标滚轮更改值 |