mcpField
S
syncfusion-wpf-calendar

syncfusion-wpf-calendar

github.com/syncfusion设计与 UI5158 次安装1 周前更新
代码仓库

关于 syncfusion-wpf-calendar

面向 WPF 开发者的 Syncfusion CalendarEdit 实现指南,用于在应用中选择和管理日期。指南介绍单选与多选、日期限制、视图导航及外观定制。

主要功能

  1. 01单日期和多日期选择
  2. 02日、月、年与十年视图导航
  3. 03最小和最大日期限制
  4. 04屏蔽特定日期范围
  5. 05颜色、画笔与动画定制
  6. 06RTL 与文化设置支持

适用场景

  1. 01构建预约或活动日期选择界面
  2. 02限制表单中可选的日期范围
  3. 03屏蔽不可预约的日期
  4. 04创建支持多选的日历界面

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/syncfusion/wpf-ui-components-skills --skill syncfusion-wpf-calendar

安装后在 Claude Code 中输入/syncfusion-wpf-calendar确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
appearance.md
date-selection.md
getting-started.md
navigation.md
restrict-dates.md

详细介绍

WPF 日历(CalendarEdit)实现指南

CalendarEdit 控件为 WPF 应用提供全面的日历 UI,用于选择和管理日期。它支持单日和多日选择、日期范围限制、可自定义外观,以及从日视图到十年视图的强大导航模式。

何时使用此技能

  • 日期选择: 需要用户选择一个或多个日期时
  • 日历 UI: 构建支持月份/年份导航的日历控件
  • 日期限制: 实现日期范围限制或屏蔽特定日期
  • 日程安排: 创建预订、预约或事件选择界面
  • 日期操作: 使用日历方法进行日期运算(增加天数、月份等)
  • 外观自定义: 设置日历颜色、画笔和视觉属性
  • 多语言支持: 支持 RTL(从右到左)布局和不同区域设置

组件概述

主要功能:

  • 支持从 0 年到 9999 年的日期
  • 单日和多日选择模式
  • 日、月、年和十年导航视图
  • 最小/最大日期限制和禁用日期屏蔽
  • 可自定义颜色、画笔和动画
  • RTL 和区域设置支持
  • 内置动画,实现流畅过渡

文档和导航指南

入门

📄 阅读: references/getting-started.md

  • 安装和程序集设置
  • 通过设计器、XAML 和 C# 添加 CalendarEdit
  • 基本控件结构和初始设置
日期选择

📄 阅读: references/date-selection.md

  • 选择单个日期(通过鼠标单击或以编程方式)
  • 选择多个日期(拖动选择和 Ctrl+单击)
  • 使用 Date 和 SelectedDates 属性
导航功能

📄 阅读: references/navigation.md

  • 在日、月、年和十年模式之间导航
  • 标题导航、键盘快捷键和动画控件
  • 自定义标题外观和动画时长
限制日期选择

📄 阅读: references/restrict-dates.md

  • 设置日期范围限制(MinDate 和 MaxDate)
  • 隐藏或显示范围外的禁用日期
  • 禁用所有日期选择或屏蔽特定日期范围
外观和自定义

📄 阅读: references/appearance.md

  • 自定义前景色、背景色和画笔颜色
  • RTL 布局支持和流向
  • 用于日期运算的日历对象方法

快速开始

基本 XAML 设置
<Window x:Class="CalendarDemo.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="Calendar Demo" Height="450" Width="500">
    <Grid>
        
        <syncfusion:CalendarEdit Name="calendarEdit"
                                 Height="250"
                                 Width="300"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Center"/>
    </Grid>
</Window>
基本 C# 设置
using Syncfusion.Windows.Shared;

CalendarEdit calendarEdit = new CalendarEdit();
calendarEdit.Height = 250;
calendarEdit.Width = 300;

// Get selected date
DateTime selectedDate = calendarEdit.Date;

// Set selected date programmatically
calendarEdit.Date = new DateTime(2024, 3, 15);

常见模式

模式 1:限制日期范围并选择单个日期
// Allow only dates in March 2024
calendarEdit.MinDate = new DateTime(2024, 3, 1);
calendarEdit.MaxDate = new DateTime(2024, 3, 31);
calendarEdit.Date = new DateTime(2024, 3, 15);

// Get the selected date
DateTime selectedDate = calendarEdit.Date;
模式 2:选择多个日期
// Enable multiple date selection
calendarEdit.AllowMultiplySelection = true;

// Select multiple dates by dragging or Ctrl+clicking
// Retrieve all selected dates
var selectedDates = calendarEdit.SelectedDates;
模式 3:屏蔽特定日期(禁用日期)
// Block specific date ranges
calendarEdit.BlackoutDates.Add(new DateTime(2024, 3, 5));
calendarEdit.BlackoutDates.Add(new DateTime(2024, 3, 20));

// Users cannot select these dates
calendarEdit.Date = new DateTime(2024, 3, 15);
模式 4:自定义日历外观
using System.Windows.Media;

// Customize colors
calendarEdit.Foreground = Brushes.Blue;
calendarEdit.Background = Brushes.White;
calendarEdit.MouseOverForeground = Brushes.Red;
calendarEdit.MouseOverBackground = Brushes.Lavender;

// Customize header
calendarEdit.HeaderBackground = Brushes.Green;
calendarEdit.HeaderForeground = Brushes.Yellow;

关键属性参考

属性类型描述
DateDateTime获取或设置当前选中的日期
SelectedDatesCollection在多选模式下获取所有选中的日期
AllowMultiplySelectionbool启用或禁用多日期选择
MinDateDateTime设置可选择的最早日期
MaxDateDateTime设置可选择的最晚日期
BlackoutDatesCollection包含不可选择的日期
DisableDateSelectionbool禁用日期选择(仍可选择月份和年份)
MinMaxHiddenbool隐藏 MinDate/MaxDate 范围之外的日期
HeaderBackgroundBrush自定义标题栏背景颜色
HeaderForegroundBrush自定义标题栏文本颜色
ChangeModeTimeint模式切换的动画时长(毫秒)
FrameMovingTimeint月份切换的动画时长(毫秒)

后续步骤: 根据要实现的功能选择上方的参考文件。如果是首次设置 CalendarEdit,请从“入门指南”开始。

评论

支持 Markdown