WP8日历(含农历)APP

WP8日历(含农历)APP UI XAML(部分)

<phone:PhoneApplicationPage xmlns:CustomControl="clr-namespace:CalendarApp.CustomControl"
xmlns:Controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
x:Class="CalendarApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
Loaded="PhoneApplicationPage_Loaded"> <Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel x:Name="SPCalendar" Margin="0" Orientation="Vertical">
<TextBlock Name="txtHead" Text="" Style="{StaticResource titleCss}" /> <!-- 日历头部 -->
<StackPanel Orientation="Vertical">
<!-- 日历button -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Image Source="/Images/left.png" ManipulationStarted="Image_ManipulationStarted" />
<StackPanel Orientation="Horizontal" ManipulationStarted="StackPanel_ManipulationStarted">
<TextBlock Name="txtYear" Text="2014" Style="{StaticResource CHeadCss}" Width="110" />
<TextBlock Text="年" Style="{StaticResource CHeadCss}" /> <TextBlock Name="txtMonth" Text="04" Style="{StaticResource CHeadCss}" Width="55" />
<TextBlock Text="月" Style="{StaticResource CHeadCss}" />
</StackPanel>
<Image Source="/Images/right.png" ManipulationStarted="Image_ManipulationStarted" />
</StackPanel> <!-- 日历标题 -->
<StackPanel Orientation="Horizontal">
<TextBlock Text="日" Style="{StaticResource CTitlerGreen}" />
<TextBlock Text="一" Style="{StaticResource CTitleCss}" />
<TextBlock Text="二" Style="{StaticResource CTitleCss}" />
<TextBlock Text="三" Style="{StaticResource CTitleCss}" />
<TextBlock Text="四" Style="{StaticResource CTitleCss}" />
<TextBlock Text="五" Style="{StaticResource CTitleCss}" />
<TextBlock Text="六" Style="{StaticResource CTitlerGreen}" />
</StackPanel>
</StackPanel> <!-- 日历内容 -->
<Grid Name="gCalendar" Background="Gray" Width="480" Height="615">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</StackPanel>
</Grid>
</phone:PhoneApplicationPage>

后台CS參考代码(部分):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using CalendarApp.Resources;
using System.Collections.ObjectModel;
using Model;
using ChineseCalendar;
using CalendarApp.PageCode;
using CalendarApp.CustomControl;
using Microsoft.Phone.Controls.Primitives; namespace CalendarApp
{
public partial class MainPage : PhoneApplicationPage
{
#region 全局变量
/// <summary>
/// BGDateWeek 当月第一天星期数
/// </summary>
int BGDateWeek = new int(); /// <summary>
/// ObservableCollection<CalendarModel> myCalendar
/// </summary>
ObservableCollection<CalendarModel> myCalendar = new ObservableCollection<CalendarModel> { };
#endregion public MainPage()
{
InitializeComponent();
} private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
//当前日期数据
DateTime dt = DateTime.Now;
if (this.NavigationContext.QueryString.Count > 0 && this.NavigationContext.QueryString["t"] != null)
if (!DateTime.TryParse(this.NavigationContext.QueryString["t"].ToString(), out dt)) dt = DateTime.Now; this.txtYear.Text = dt.ToString("yyyy");
this.txtMonth.Text = dt.ToString("MM"); //载入当月日期数据
GetMonthDate(dt.ToString("yyyy-MM-dd"));
} #region 依据指定时间获取日历数据
/// <summary>
/// 依据指定时间获取日历数据
/// </summary>
/// <param name="dtMonth">时间 yyyy-MM</param>
public void GetMonthDate(String dtMonth)
{
//初始化參数
DateTime dt = DateTime.Now;
if (!DateTime.TryParse(dtMonth, out dt)) dt = DateTime.Now; //获取选中日期的第一天、最后一天。以及第一天星期几
DateTime BGDate, EDDate, GLDate;
BGDate = new DateTime(dt.Year, dt.Month, 1);
EDDate = BGDate.AddMonths(1).AddDays(-1);
getWeekIndex(BGDate.DayOfWeek.ToString()); //自己定义控件
CustomControl.CustomDate cd = null;
CustomControl.CustomDateGreen cdGreen = null; //初始化变量
CalendarModel item = null; //清空
this.gCalendar.Children.Clear(); //循环加入数据
int row = 0, col = 0;
for (int i = 0, len = (EDDate - BGDate).Days; i <= len; i++)
{
//设定行和列
if (i == 0)
col = BGDateWeek;
else col++; if (col > 6)
{
col = 0;
row++;
} GLDate = BGDate.AddDays(i);
item = new CalendarModel()
{
GLDay = GLDate.ToString("dd"),
GLDate = GLDate.ToString("yyyy-MM-dd"), NLDay = ChineseCalendarDate.GetChineseDate(GLDate),
NLDate = ChineseCalendarDate.GetChineseDateTime(GLDate)
}; //年信息
String year = item.NLDate.Substring(0, item.NLDate.IndexOf("年") + 1);
this.txtHead.Text = "农历" + year; //绑定数据
if (col == 0 || col == 6)
{
cdGreen = new CustomDateGreen();
cdGreen.DataContext = item;
Grid.SetColumn(cdGreen, col);
Grid.SetRow(cdGreen, row);
this.gCalendar.Children.Add(cdGreen);
}
else
{
cd = new CustomDate();
cd.DataContext = item;
Grid.SetColumn(cd, col);
Grid.SetRow(cd, row);
this.gCalendar.Children.Add(cd);
}
}
}
#endregion #region 获取星期索引
/// <summary>
/// 获取星期索引
/// </summary>
/// <param name="week"></param>
private void getWeekIndex(String week)
{
switch (week)
{
case "Monday": //周一
BGDateWeek = 1;
break;
case "Tuesday": //周二
BGDateWeek = 2;
break;
case "Wednesday"://周三
BGDateWeek = 3;
break;
case "Thursday"://周四
BGDateWeek = 4;
break;
case "Friday": //周五
BGDateWeek = 5;
break;
case "Saturday"://周六
BGDateWeek = 6;
break;
case "Sunday": //周末
BGDateWeek = 0;
break;
}
}
#endregion #region 时间选择
/// <summary>
/// 时间选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Image_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
Image image = (Image)sender;
if (image != null)
{
int y = int.Parse(this.txtYear.Text);
int m = int.Parse(this.txtMonth.Text); if (((System.Windows.Media.Imaging.BitmapImage)(image.Source)).UriSource.ToString().Contains("left.png"))
{
//时间递减
if (m - 1 <= 0)
{
//前一年
this.txtMonth.Text = "12";
this.txtYear.Text = (y - 1).ToString().Trim();
}
else
{
//当年,月递减
m--;
if (m == 0) m = 1;
this.txtMonth.Text = m >= 10 ? m.ToString() : "0" + m.ToString();
}
}
else
{
//时间递增
if (m + 1 > 12)
{
//后一年
this.txtMonth.Text = "01";
this.txtYear.Text = (y + 1).ToString().Trim();
}
else
{
//当年,月递增
m++;
this.txtMonth.Text = m >= 10 ? m.ToString() : "0" + m.ToString();
}
} //获取新时间
GetNewDate();
}
}
#endregion #region 相应时间选择
/// <summary>
/// 相应时间选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StackPanel_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
String time = this.txtYear.Text + "-" + this.txtMonth.Text;
this.NavigationService.Navigate(new Uri("/CustomControl/CustomDatePicker.xaml? t=" + time, UriKind.Relative));
}
#endregion #region 获取新时间
/// <summary>
/// 获取新时间
/// </summary>
public void GetNewDate()
{
//当前日期数据
DateTime dt = DateTime.Parse(this.txtYear.Text.Trim() + "-" + this.txtMonth.Text.Trim()); this.txtYear.Text = dt.ToString("yyyy");
this.txtMonth.Text = dt.ToString("MM"); //载入当月日期数据
GetMonthDate(dt.ToString("yyyy-MM-dd"));
}
#endregion
}
}
备注:因为在本实例中无法 使用 ChineseLunisolarCalendar 类 无法获取 中国农历的准确数据
      案例中的农历数据 有误。如有能人帮助解决。
      将不胜感激!
      自己定义 类 依据公历获取 农历日期数据: http://blog.csdn.net/yimiyuangguang/article/details/24301933

实例下载:

http://pan.baidu.com/s/1gd5UU5d

效果图:

WP8日历(含农历)APP的更多相关文章

  1. Google日历添加农历、节日和天气插件(步骤)

    Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...

  2. iOS 给三方日历加上农历

    首先创建一个农历文件 LunarCalendar.h // // LunarCalendar.h // Hnair4iPhone // // Created by yingkong1987 on 13 ...

  3. 带节日和农历的js日历 带农历的脚本:

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  4. iOS日历显示农历信息

    第一次接触到日历的开发,表示需要学习的东西还有很多呢! 关于日历的开发,如果不进行相关设置的话,默认是没有农历的,需要我们进行设置. 核心Demo如下: monthArr = [NSArray arr ...

  5. wp8.1 Study10:APP数据存储

    一.理论 1.App的各种数据在WP哪里的? 下图很好介绍了这个问题.有InstalltionFolder, knownFolder, SD Card... 2.一个App的数据存储概览 主要分两大部 ...

  6. wp8.1 Study6: App的生命周期管理

    一.概述 应用程序的生命周期详解可以参照Windows8.1开发中msdn文档http://msdn.microsoft.com/library/windows/apps/hh464925.aspx ...

  7. java 日历计算农历和节假日的工具类

    背景 业务需求需要后端提供这样的接口,网上找了很多java代码例子,虽然功能实现了 但是不完善,特别是节日那一块儿.然后百度发现有这样的插件,但是信息也是java后端提供的非js 然后在开源js插件找 ...

  8. 一个小巧,也很nice的“小日历”--一个Android App

    一个小巧也很Nice的“小日历” 背景 因为,常用日历记一些事情,Android自带的日历,如果有事情,会显示一个小点,然后点击进去后才能看到事情的具体内容,不是很方便. 所以,写了一个“小日历” 特 ...

  9. wp8.1 Study11:APP里文件读写和使用XML和Json序列化

    一.文件读写 1.基本操作(使用FileIO API) 这个方法在上一个stduy已经学过,那么贴出来复习下,代码如下: private async void writeTextToLocalStor ...

随机推荐

  1. Hexo 添加自定义的内置标签

    灵感 想设计一个记录自已骑行的页面,显示时间.地点.路线图等信息.方便以后做一些留念.定位想实现下面类似的效果.参考:<特效>      实现方案也比较简单,反键查看源码.直接Copy,在 ...

  2. 【VC++学习笔记一】MFC操作Excel

    最近在做一个读取Excel的功能,之前也做过相关的,但总是零零闪闪的,趁着正在劲头上,归纳一下: 利用Automation添加相关的类,在Excel2010中可以在安装文件夹下直接点击Excel.ex ...

  3. 【Henu ACM Round#16 C】Graph and String

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 根据题意:先明确以下规则: 1.如果两个点之间没有边,那么这两个点只能是a或c,且不能相同 2.如果两个点之间有边,那么他们之间的差 ...

  4. HDU 2883 kebab

    kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...

  5. HBase概念学习(八)开发一个类twitter系统之表设计

    这边文章先将可能的需求分析一下,设计出HBase表,下一步再開始编写client代码. TwiBase系统 1.背景 为了加深HBase基本概念的学习,參考HBase实战这本书实际动手做了这个样例. ...

  6. 实验记录三 通用输入输出(GPIO)

    之前把全部程序都跑了一次后,得到了导师下一步的安排. 例如以下: 1.编写一个程序.实如今LCD上显示一个万年历,包含年月日 星期 还有室内的温度.2.编写一个程序,将原来的交通灯改为跑马灯. 期限是 ...

  7. [当我在研究Cocos-2dx的源代码时,我在想什么]-Ref类,一切的起源

    [名词解释]      引用计数:引用计数是现代内存管理中常常使用到的一个概念.它的基本思想是通过计数方式实现多个不同对象同一时候引用一个共享对象,详细地讲,当创建一个对象的实例并在堆上分配内存时,对 ...

  8. FFmpeg的HEVC解码器源码简单分析:解码器主干部分

    ===================================================== HEVC源码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpeg ...

  9. vue中的插槽slot理解

    本篇文章参考赛冷思的个人博客 1.函数默认传参 在我们写js函数我们的可能会给他们一个默认的参数,写法是 function show(age,name){ var age = age || 20; v ...

  10. POj 2159 Dividing

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71453   Accepted: 18631 Descri ...