网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > Silverlight > 正文

有关SilverlightCalendar组件(日历组件)的研究

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

组件所在命名空间:

System.Windows.Controls

组件常用属性:

SelectedDate:获取或设置当前被选中的日期

DisplayDate:获取或设置日期以显示

DisplayDateStart:获取或设置被显示的第一个日期

DisplayDateEnd:获取或设置被显示的最后一个日期

SelectionMode:获取或设置Calendar组件的选取模式

None:设置日历为不可选

SingleDate:只能选择单一日期

SingleRange:只能连续选取日期

MultipleRange:能连续或者间隔地(通过按住Ctrl键)选取日期

BlackoutDates:获取或设置被标记为不可选的一个日期集合

SelectedDates:获取被选中的一个日期集合

IsTodayHighlighted:是否将今日日期高亮显示。

组件常用事件:

DisplayDateChanged:显示日期改变

DisplayModeChanged:显示模式改变

SelectedDatesChanged:被选中日期改变

实例:

说明:在属性方面应当重点掌握该组件的BlackoutDates和SelectedDates属性(可用于数据库的交互),在事件方面应当重点掌握SelectedDatesChanged事件。

 效果图:


[原始状态]


[显示日期范围]


[SingleRange]


[MultipleRange和BlackoutDates]


[背景图片和背景视频]

代码段:
MainPage.xaml代码:(由Microsoft Expression Blend 3设计)

  1. <UserControl 
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  4.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  5.     mc:Ignorable="d" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" x:Class="Calendar.MainPage" 
  6.     xmlns:src="clr-namespace:Calendar" 
  7. d:DesignWidth="640" d:DesignHeight="480" Width="640" Height="480"> 
  8. <!--作为cbBackgroundImage的数据源--> 
  9.     <UserControl.Resources> 
  10.         <src:picsrcProvider x:Key="picsrcProvider"></src:picsrcProvider> 
  11.     </UserControl.Resources> 
  12.     
  13.     <Grid x:Name="LayoutRoot" Width="640" Height="480" Background="White"> 
  14.      <controls:Calendar x:Name="cal" Height="164" HorizontalAlignment="Left" Margin="31,24,0,0" VerticalAlignment="Top" Width="177" FontSize="16"/> 
  15.         <Canvas> 
  16.             <MediaElement x:Name="media" AutoPlay="False" IsMuted="True" IsHitTestVisible="False" Source="backvideo.wmv" Margin="141,0,0,35" Visibility="Collapsed"></MediaElement> 
  17.         </Canvas> 
  18.      <ComboBox x:Name="cbSelectionMode" HorizontalAlignment="Right" Margin="0,112,100,0" Width="177" Height="28" SelectedIndex="1" VerticalAlignment="Top" d:LayoutOverrides="Height"> 
  19.          <ComboBoxItem Content="None"/> 
  20.          <ComboBoxItem Content="SingleDate"/> 
  21.          <ComboBoxItem Content="SingleRange"/> 
  22.          <ComboBoxItem Content="MultipleRange"/> 
  23.      </ComboBox> 
  24.      <dataInput:Label Height="19" Margin="240,112,294,0" VerticalAlignment="Top" Content="日历选取模式:" FontSize="16"/> 
  25.      <dataInput:Label Height="24" Margin="241,24,256,0" VerticalAlignment="Top" Content="显示日期范围:" FontSize="16"/> 
  26.      <dataInput:Label Height="25" HorizontalAlignment="Left" Margin="240,66,0,0" VerticalAlignment="Top" Width="29" Content="从" FontSize="16"/> 
  27.      <dataInput:Label FontSize="16" Height="25" HorizontalAlignment="Right" Margin="0,66,198,0" VerticalAlignment="Top" Width="29" Content="到"/> 
  28.      <controls:DatePicker x:Name="dpShowFrom" Height="25" Margin="269,66,240,0" VerticalAlignment="Top" Width="131"/> 
  29.      <controls:DatePicker x:Name="dpShowTo" Height="25" HorizontalAlignment="Right" Margin="0,66,59,0" VerticalAlignment="Top" Width="131"/> 
  30.      <dataInput:Label HorizontalAlignment="Left" Margin="33,214,0,238" Width="134" Content="当前选中的日期:" FontSize="16"/> 
  31.      <TextBox x:Name="tbSelectedDate" Height="33" HorizontalAlignment="Left" Margin="33,0,0,188" VerticalAlignment="Bottom" Width="175" TextWrapping="Wrap" FontSize="16"/> 
  32.      <dataInput:Label FontSize="16" Height="24" Margin="241,159,256,0" VerticalAlignment="Top" Content="不可选日期范围:"/> 
  33.      <dataInput:Label FontSize="16" Height="25" HorizontalAlignment="Left" Margin="240,201,0,0" VerticalAlignment="Top" Width="29" Content="从"/> 
  34.      <dataInput:Label FontSize="16" Height="25" HorizontalAlignment="Right" Margin="0,201,198,0" VerticalAlignment="Top" Width="29" Content="到"/> 
  35.      <controls:DatePicker x:Name="dpUnselectedFrom" Height="25" Margin="269,201,240,0" VerticalAlignment="Top" Width="131"/> 
  36.      <controls:DatePicker x:Name="dpUnselectedTo" Height="25" HorizontalAlignment="Right" Margin="0,201,59,0" VerticalAlignment="Top" Width="131"/> 
  37.      <dataInput:Label Margin="240,237,256,214" Content="已选中日期的集合:" FontSize="16"/> 
  38.      <TextBlock x:Name="tbSelectedDateCollection" Height="70" Margin="241,0,59,144" VerticalAlignment="Bottom" Text="&lt;None&gt;" TextWrapping="Wrap" Width="340" Foreground="Black"/> 
  39.      <dataInput:Label FontSize="16" Margin="241,0,256,112" Content="不可选日期的集合:" Height="24" VerticalAlignment="Bottom"/> 
  40.      <TextBlock x:Name="tbUnselectedDataCollection" Height="63" Margin="241,0,59,35" VerticalAlignment="Bottom" Text="&lt;None&gt;" TextWrapping="Wrap" Width="340"/> 
  41.      <Button x:Name="btnClear" Height="25" HorizontalAlignment="Right" Margin="0,201,8,0" VerticalAlignment="Top" Width="47" Content="清除" FontSize="14.667"/> 
  42.      <Button x:Name="btnClearSelectedDate" Height="25" HorizontalAlignment="Right" Margin="0,66,8,0" VerticalAlignment="Top" Width="47" Content="清除" FontSize="14.667"/> 
  43.      <dataInput:Label Height="30" HorizontalAlignment="Left" Margin="33,0,0,154" VerticalAlignment="Bottom" Width="106" Content="背景图片:" FontSize="16"/> 
  44.      <ComboBox x:Name="cbBackgroundImage" Height="28" ItemsSource="{Binding picsrc,Source={StaticResource picsrcProvider}}" HorizontalAlignment="Left" Margin="35,0,0,112" VerticalAlignment="Bottom" Width="173"/> 
  45.      <CheckBox x:Name="cbBackgroundVideo" Height="26" HorizontalAlignment="Left" Margin="35,0,0,57" VerticalAlignment="Bottom" Width="173" Content="视频背景" FontSize="16"/> 
  46.   </Grid> 
  47. </UserControl> 

MainPage.xaml.cs代码:

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Net; 
  5. using System.Windows; 
  6. using System.Windows.Controls; 
  7. using System.Windows.Documents; 
  8. using System.Windows.Input; 
  9. using System.Windows.Media; 
  10. using System.Windows.Media.Animation; 
  11. using System.Windows.Media.Imaging;//目的:为了创建ImageBrush而导入的命名空间。 
  12.   
  13. namespace Calendar 
  14.     public class picsrcProvider//cbBackgroundImage的数据源 
  15.     { 
  16.         public List<string> picsrc 
  17.         { 
  18.             get 
  19.             { 
  20.                 return new List<string> { "images/calbackground.PNG""images/calbackground2.PNG" }; 
  21.             } 
  22.         } 
  23.     } 
  24.   
  25.     public partial class MainPage : UserControl 
  26.     { 
  27.         //定义全局变量 
  28.         ImageBrush bgimg = new ImageBrush(); 
  29.         VideoBrush bgvideo = new VideoBrush(); 
  30.   
  31.         public MainPage() 
  32.         { 
  33.             InitializeComponent(); 
  34. //注册控件触发事件的处理函数,个人建议使用该方法,以便于代码与界面设计分离 
  35.             this.cal.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(cal_SelectedDatesChanged); 
  36.             this.cbSelectionMode.SelectionChanged += new SelectionChangedEventHandler(cbSelectionMode_SelectionChanged); 
  37.             this.dpShowFrom.SelectedDateChanged += new EventHandler<SelectionChangedEventArgs>(dpShowFrom_SelectedDateChanged); 
  38.             this.dpShowTo.SelectedDateChanged += new EventHandler<SelectionChangedEventArgs>(dpShowTo_SelectedDateChanged); 
  39.             this.dpUnselectedTo.SelectedDateChanged += new EventHandler<SelectionChangedEventArgs>(dpUnselectedTo_SelectedDateChanged); 
  40.             this.btnClear.Click += new RoutedEventHandler(btnClear_Click); 
  41.             this.btnClearSelectedDate.Click += new RoutedEventHandler(btnClearSelectedDate_Click); 
  42.             this.cbBackgroundImage.SelectionChanged += new SelectionChangedEventHandler(cbBackgroundImage_SelectionChanged); 
  43.             this.Loaded += new RoutedEventHandler(MainPage_Loaded); 
  44.             this.cbBackgroundVideo.Checked += new RoutedEventHandler(cbBackgroundVideo_Checked); 
  45.             this.media.MediaEnded += new RoutedEventHandler(media_MediaEnded); 
  46.         } 
  47.   
  48.         void media_MediaEnded(object sender, RoutedEventArgs e) 
  49.         {//背景视频的重播 
  50.             media.Position = TimeSpan.FromSeconds(0); 
  51.             media.Play(); 
  52.         } 
  53.   
  54.         void cbBackgroundVideo_Checked(object sender, RoutedEventArgs e) 
  55.         {//背景视频的处理 
  56.             bool? state = cbBackgroundVideo.IsChecked; 
  57.             if (state == true
  58.             { 
  59.                 media.Play(); 
  60.                 bgvideo.SourceName = "media"
  61.                 bgvideo.Stretch = Stretch.Fill; 
  62.                 bgvideo.Opacity = 0.5; 
  63.                 cal.Background = bgvideo; 
  64.             } 
  65.         } 
  66.   
  67.         void cbBackgroundImage_SelectionChanged(object sender, SelectionChangedEventArgs e) 
  68.         {//背景图片的选择 
  69.             string imgSource = cbBackgroundImage.SelectedItem.ToString(); 
  70.             bgimg.ImageSource = new BitmapImage(new Uri(@imgSource, UriKind.Relative)); 
  71.             bgimg.Opacity = 0.5; 
  72.             bgimg.Stretch = Stretch.Fill; 
  73.             cal.Background = bgimg; 
  74.         } 
  75.   
  76.         void MainPage_Loaded(object sender, RoutedEventArgs e) 
  77.         { 
  78.             media.Play(); 
  79.         } 
  80.   
  81.         void btnClearSelectedDate_Click(object sender, RoutedEventArgs e) 
  82.         { 
  83.             cal.SelectedDates.Clear(); 
  84.             tbSelectedDate.Text = String.Empty; 
  85.             tbSelectedDateCollection.Text = String.Empty; 
  86.         } 
  87.   
  88.         void btnClear_Click(object sender, RoutedEventArgs e) 
  89.         { 
  90.             cal.BlackoutDates.Clear(); 
  91.             tbUnselectedDataCollection.Text = String.Empty; 
  92.         } 
  93.   
  94.         void cal_SelectedDatesChanged(object sender, SelectionChangedEventArgs e) 
  95.         {//设置日历的可选日期集合并且显示 
  96.             try 
  97.             { 
  98.                 tbSelectedDate.Text = ((DateTime)cal.SelectedDate).ToShortDateString(); 
  99.                 tbSelectedDateCollection.Text = String.Empty; 
  100.                 cal.SelectedDates.ToList().ForEach(x => tbSelectedDateCollection.Text += x.ToShortDateString() + " "); 
  101.             } 
  102.             catch { } 
  103.         } 
  104.   
  105.         void dpUnselectedTo_SelectedDateChanged(object sender, SelectionChangedEventArgs e) 
  106.         {//设置日历的不可选日期集合并且显示 
  107.             try 
  108.             { 
  109.                 if (dpUnselectedFrom.SelectedDate != null
  110.                 { 
  111.                     cal.BlackoutDates.Clear(); 
  112.                     cal.BlackoutDates.Add(new CalendarDateRange((DateTime)dpUnselectedFrom.SelectedDate, (DateTime)dpUnselectedTo.SelectedDate)); 
  113.                     tbUnselectedDataCollection.Text = String.Empty; 
  114.                     cal.BlackoutDates.ToList().ForEach(x => tbUnselectedDataCollection.Text += "从" + x.Start.ToShortDateString() + "到" + x.End.ToShortDateString()); 
  115.                 } 
  116.             } 
  117.             catch { } 
  118.         } 
  119.   
  120.         void dpShowTo_SelectedDateChanged(object sender, SelectionChangedEventArgs e) 
  121.         { 
  122.             cal.DisplayDateEnd = dpShowTo.SelectedDate; 
  123.         } 
  124.   
  125.         void dpShowFrom_SelectedDateChanged(object sender, SelectionChangedEventArgs e) 
  126.         { 
  127.             cal.DisplayDateStart = dpShowFrom.SelectedDate; 
  128.         } 
  129.   
  130.         void cbSelectionMode_SelectionChanged(object sender, SelectionChangedEventArgs e) 
  131.         {//处理日历的选择模式 
  132.             string mode = ((ComboBoxItem)cbSelectionMode.SelectedItem).Content.ToString(); 
  133.             switch(mode) 
  134.             { 
  135.                 case "None"
  136.                 cal.SelectionMode = CalendarSelectionMode.None; 
  137.                 break
  138.                 case "SingleDate"
  139.                 cal.SelectionMode = CalendarSelectionMode.SingleDate; 
  140.                 break
  141.                 case "SingleRange"
  142.                 cal.SelectionMode = CalendarSelectionMode.SingleRange; 
  143.                 break
  144.                 case "MultipleRange"
  145.                 cal.SelectionMode = CalendarSelectionMode.MultipleRange; 
  146.                 break
  147.             } 
  148.         } 
  149.     } 
设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师