DateTimePicker.xaml.cs
3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/****************************************************************
* 作 者 :姜 彦
* 项目名称 :RCS.WinClient.Controls.View
* 控件名称 :DateTimePicker
* 命名空间 :RCS.WinClient.Controls.View
* CLR 版本 :4.0.30319.42000
* 创建时间 :2017/8/4 9:10:14
* 当前版本 :1.0.0.1
* My Email:771078740@qq.com
* 描述说明:
*
* 修改历史:
*
****************************************************************
* Copyright @ JiangYan 2018 All rights reserved
****************************************************************/
using System;
using System.Windows;
using System.Windows.Controls;
using System.Drawing;
namespace RCS.WinClient.Controls.View
{
[ToolboxBitmap(typeof(DateTimePicker), "DateTimePicker.bmp")]
/// <summary>
/// DateTimePicker.xaml 的交互逻辑
/// </summary>
public partial class DateTimePicker : UserControl
{
public DateTimePicker()
{
InitializeComponent();
this.border1.Width = double.IsNaN(Width) ? 150 : Width;
this.border1.Height = double.IsNaN(Height) ? 25 : Height;
this.iconButton1.Width = double.IsNaN(Width) ? 19 : Width * 0.2;
this.iconButton1.Height = double.IsNaN(Height) ? 18 : Height * 0.65;
this.textBlock1.Margin = Padding;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="txt"></param>
public DateTimePicker(string txt)
: this()
{
// this.textBox1.Text = txt;
}
#region 事件
/// <summary>
/// 日历图标点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void iconButton1_Click(object sender, RoutedEventArgs e)
{
if (popChioce.IsOpen == true)
{
popChioce.IsOpen = false;
}
TDateTimeView dtView = new TDateTimeView(textBlock1.Text);// TDateTimeView 构造函数传入日期时间
dtView.DateTimeOK += (dateTimeStr) => //TDateTimeView 日期时间确定事件
{
textBlock1.Text = dateTimeStr;
DateTime = Convert.ToDateTime(dateTimeStr);
popChioce.IsOpen = false;//TDateTimeView 所在pop 关闭
};
popChioce.Child = dtView;
popChioce.IsOpen = true;
}
/// <summary>
/// DateTimePicker 窗体登录事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
//DateTime dt = DateTime.Now;
DateTime dt = this.DateTime == default ? DateTime.Now : this.DateTime;
textBlock1.Text = dt.ToString("yyyy/MM/dd HH:mm:ss");//"yyyyMMddHHmmss"
DateTime = dt;
// DateTime = Convert.ToDateTime(textBlock1.Text);
}
#endregion
#region 属性
/// <summary>
/// 日期时间
/// </summary>
public DateTime DateTime { get; set; }
#endregion
}
}