WPF TimePicker控件源代码

本文档详细介绍了如何使用C#实现一个自定义的WPF TimePicker控件,包括TextBox部分的处理、时间增加和减少的按钮功能,以及属性设置如MinTime和MaxTime的验证和限制。
摘要由CSDN通过智能技术生成

#region [       Using namespaces       ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using AFC.WS.UI.Common;
using Microsoft.Windows.Controls;
using System.Windows.Controls.Primitives;
#endregion

namespace AFC.WS.UI.CommonControls
{

    [TemplatePart(Name = TimePicker.ElementHourTextBox, Type = typeof(TextBox))]

    [TemplatePart(Name = TimePicker.ElementMinuteTextBox, Type = typeof(TextBox))]

    [TemplatePart(Name = TimePicker.ElementSecondTextBox, Type = typeof(TextBox))]

    [TemplatePart(Name = TimePicker.ElementIncrementButton, Type = typeof(RepeatButton))]

    [TemplatePart(Name = TimePicker.ElementDecrementButton, Type = typeof(RepeatButton))]

    public partial class TimePicker : UserControl, ICommonEdit
    {

        #region [       Constants       ]

        private const string ElementHourTextBox = "PART_HourTextBox";

        private const string ElementMinuteTextBox = "PART_MinuteTextBox";

        private const string ElementSecondTextBox = "PART_SecondTextBox";

        private const string ElementIncrementButton = "PART_IncrementButton";

        private const string ElementDecrementButton = "PART_DecrementButton";

        private static TimeSpan MinValidTime = new TimeSpan(0, 0, 0);

        private static TimeSpan MaxValidTime = new TimeSpan(23, 59, 59);

        private TextBox selectedTextBox = null;

        #endregion

        #region [       Staic Constructor       ]
        static TimePicker()
        {

            DefaultStyleKeyProperty.OverrideMetadata(typeof(TimePicker), new FrameworkPropertyMetadata(typeof(TimePicker)));

        }
        #endregion

        #region [        Constructor       ]
        public TimePicker()
        {

            SelectedTime = DateTime.Now.TimeOfDay;

        }

 

        #endregion Ctor

        #region [       Data       ]


        private TextBox hourTextBox;

        private TextBox minuteTextBox;

        private TextBox secondTextBox;

        private RepeatButton incrementButton;

        private RepeatButton decrementButton;

        #endregion Data

        #region [       Public Properties  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值