DatePicker的BlackoutDates,日曆控制項可選範圍設定。,datetimepicker控制項

來源:互聯網
上載者:User

DatePicker的BlackoutDates,日曆控制項可選範圍設定。,datetimepicker控制項

簡述:

       在已存在的時間列表中,存在以下條件

         1、當日及以上的時間可選。

         2、已存在的時間可選的範圍是存在的時間的第二天,到下個月的1日。

 

畫面代碼:

<UserControl x:Class="SilverlightApplication2.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"    mc:Ignorable="d"    d:DesignHeight="300" d:DesignWidth="400" >    <Grid x:Name="LayoutRoot" Background="White">        <sdk:DatePicker Height="23" HorizontalAlignment="Left" Margin="61,83,0,0" Name="datePicker1" VerticalAlignment="Top" Width="120" />    </Grid></UserControl>

 

後台代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace SilverlightApplication2{    public partial class MainPage : UserControl    {        public MainPage()        {            InitializeComponent();            InitDatePicker();        }        private void InitDatePicker()        {            List<DateTime> list = this.GetDateTime();            List<DateTime> hanTime = new List<DateTime>();            for (int i = 0; i < list.Count - 1; i++)            {                DateTime d1 = list[i];                DateTime d2 = list[i + 1];                if (i == 0)                {                    this.datePicker1.BlackoutDates.Add(new CalendarDateRange(new DateTime(), d1));                }                this.datePicker1.BlackoutDates.Add(new CalendarDateRange(d1));                DateTime dt = new DateTime(d1.Year, d1.AddMonths(1).Month, 1);                if (d1.Month != d2.Month && dt != d2)                {                    List<DateTime> hanTimeList = this.GetTimeList(d1, d2);                    this.datePicker1.BlackoutDates.Add(new CalendarDateRange(hanTimeList[0], hanTimeList[1]));                }            }            this.datePicker1.BlackoutDates.Add(new CalendarDateRange(list[list.Count - 1]));        }
        //已存在時間列表        private List<DateTime> GetDateTime()        {            List<DateTime> rtn = new List<DateTime>();            DateTime time = new DateTime(2014, 8, 12);            DateTime time3 = new DateTime(2014, 8, 15);            DateTime time1 = new DateTime(2014, 9, 27);            DateTime time2 = new DateTime(2014, 9, 28);            DateTime time4 = new DateTime(2014, 9, 30);            DateTime time7 = new DateTime(2014, 10, 1);            DateTime time5 = new DateTime(2014, 10, 12);            DateTime time6 = new DateTime(2014, 12, 1);            rtn.Add(time);            rtn.Add(time3);            rtn.Add(time1);            rtn.Add(time2);            rtn.Add(time4);            rtn.Add(time7);            rtn.Add(time5);            rtn.Add(time6);            return rtn;        }               
         //上一個時間和下一個時間移除範圍
        private List<DateTime> GetTimeList(DateTime d1, DateTime d2)        {            List<DateTime> hanTime = new List<DateTime>();            DateTime dt = d1.AddMonths(1);            hanTime.Add(new DateTime(dt.Year, dt.Month, 2));            hanTime.Add(d2.AddDays(-1));            return hanTime;        }    }}


 



 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.