当前位置: 首页 > news >正文

<c1:C1DateTimePicker的日期时间控件,控制日期可以修改,时间不能修改,另外控制开始时间的最大值比结束时间小一天

两个时间控件  

<c1:C1DateTimePicker Width="170" EditMode="DateTime" CustomDateFormat="yyyy-MM-dd" CustomTimeFormat="HH:mm:ss" Style="{StaticResource ListSearch-DateTimePicker}"  
x:Name="dateTimePicker"        PreviewKeyDown="DateTimePicker_PreviewKeyDown"  TimeIncrement="00:00:0"
PreviewTextInput="DateTimePicker_PreviewTextInput"        
MaxDate="{Binding MaxAllowedStartDate, Mode=TwoWay}"                MinDate="1/1/2000" TimeFormat="LongTime" AllowNull="False" DateTime="{Binding StoreStartTime, Mode=TwoWay}"/>
<Label Style="{StaticResource ListSearch-Label}" Content="结束时间:"/>
<c1:C1DateTimePicker Width="170" EditMode="DateTime" CustomDateFormat="yyyy-MM-dd" CustomTimeFormat="HH:mm:ss" Style="{StaticResource ListSearch-DateTimePicker}" 
x:Name="dateTimePicker1"      TimeIncrement="00:00:0"
PreviewTextInput="DateTimePicker_PreviewTextInput" PreviewKeyDown="DateTimePicker_PreviewKeyDown"
MinDate="1/1/2000" TimeFormat="LongTime" AllowNull="False" DateTime="{Binding StoreEndTime, Mode=TwoWay}"/>

点击事件控制时间不能修改

   // 禁止键盘输入(如方向键切换到时间部分)
private void DateTimePicker_PreviewKeyDown(object sender, KeyEventArgs e)
{
// 禁止方向键(可能用于切换日期/时间部分)
if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
{
e.Handled = true; // 阻止事件继续传递
}

            // 禁止输入 ':'(时间分隔符)
if (e.Key == Key.OemSemicolon )
{
e.Handled = true;
}
}

        // 禁止文本输入(如直接输入时间)
private void DateTimePicker_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
// 禁止输入 ':' 或数字(如果时间部分可能被编辑)
if (e.Text == ":" || char.IsDigit(e.Text[0]))
{
e.Handled = true;
}
}

设置开始时间的最大值 MaxAllowedStartDate

        private DateTime? _storeEndTime;
/// <summary>
/// 交期日期查询结束日期
/// </summary>
public DateTime? StoreEndTime
{
get { return _storeEndTime; }
set
{
if (_storeEndTime != value)
{
_storeEndTime = value;
// 计算 MaxDate:StoreEndTime - 1天 + 1秒
//MaxAllowedStartDate = value.Value.AddDays(-1).AddSeconds(1);
RaisePropertyChanged(() => StoreEndTime);
}
// 计算 MaxAllowedStartDate:StoreEndTime - 1天 + 1秒
if (value.HasValue)
{
MaxAllowedStartDate = value.Value.AddDays(-1).AddSeconds(1);
}
else
{
MaxAllowedStartDate = null;
}
RaisePropertyChanged(() => MaxAllowedStartDate);
}
}
//存储开始时间的最大值
public DateTime? MaxAllowedStartDate { get; set; }

效果:比如开始时间的最大值比结束时间小1天

http://www.dtcms.com/a/330310.html

相关文章:

  • git clone 支持在命令行临时设置proxy
  • 康托展开与逆康托展开
  • 词向量转化
  • RocketMQ 消息存储机制 CommitLog和ConsumerQu
  • 第八课:python的运算符
  • 从 VLA 到 VLM:低延迟RTSP|RTMP视频链路在多模态AI中的核心角色与工程实现
  • 论文分享 | Flashboom:一种声东击西攻击手段以致盲基于大语言模型的代码审计
  • 04-spring-手写spring-demo-aop0V1
  • Canal解析MySQL Binlog原理与应用
  • Unity、C#常用的时间处理类
  • Laravel 使用ssh链接远程数据库
  • 使用 Simple Floating Menu 插件轻松实现浮动联系表单
  • AI一周事件(2025年8月6日-8月12日)
  • [ Mybatis 多表关联查询 ] resultMap
  • ResourcelessTransactionManager的作用
  • 第三天-如何在DBC中描述CAN Signal的“负数/值”
  • JetPack系列教程(六):Paging——让分页加载不再“秃”然
  • 理财学习资料推荐
  • 谈一些iOS组件化相关的东西
  • C# 多线程:并发编程的原理与实践
  • C++中的STL标准模板库和string
  • Heterophily-aware Representation Learning on Heterogeneous Graphs
  • AI - 工具调用
  • AI智能体记忆策略
  • 10 ABP 模块系统
  • [转]SURREAL数据集国内下载链接
  • Deep Agents:用于复杂任务自动化的 AI 代理框架
  • nm命令和nm -D命令参数
  • 19. 重载的方法能否根据返回值类型进行区分
  • Java之String类