WP8日历(含农历)APP
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的更多相关文章
- Google日历添加农历、节日和天气插件(步骤)
Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...
- iOS 给三方日历加上农历
首先创建一个农历文件 LunarCalendar.h // // LunarCalendar.h // Hnair4iPhone // // Created by yingkong1987 on 13 ...
- 带节日和农历的js日历 带农历的脚本:
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- iOS日历显示农历信息
第一次接触到日历的开发,表示需要学习的东西还有很多呢! 关于日历的开发,如果不进行相关设置的话,默认是没有农历的,需要我们进行设置. 核心Demo如下: monthArr = [NSArray arr ...
- wp8.1 Study10:APP数据存储
一.理论 1.App的各种数据在WP哪里的? 下图很好介绍了这个问题.有InstalltionFolder, knownFolder, SD Card... 2.一个App的数据存储概览 主要分两大部 ...
- wp8.1 Study6: App的生命周期管理
一.概述 应用程序的生命周期详解可以参照Windows8.1开发中msdn文档http://msdn.microsoft.com/library/windows/apps/hh464925.aspx ...
- java 日历计算农历和节假日的工具类
背景 业务需求需要后端提供这样的接口,网上找了很多java代码例子,虽然功能实现了 但是不完善,特别是节日那一块儿.然后百度发现有这样的插件,但是信息也是java后端提供的非js 然后在开源js插件找 ...
- 一个小巧,也很nice的“小日历”--一个Android App
一个小巧也很Nice的“小日历” 背景 因为,常用日历记一些事情,Android自带的日历,如果有事情,会显示一个小点,然后点击进去后才能看到事情的具体内容,不是很方便. 所以,写了一个“小日历” 特 ...
- wp8.1 Study11:APP里文件读写和使用XML和Json序列化
一.文件读写 1.基本操作(使用FileIO API) 这个方法在上一个stduy已经学过,那么贴出来复习下,代码如下: private async void writeTextToLocalStor ...
随机推荐
- @Mapper注解在springboot中无法注入
问题① @Mapper注解报红无法注入 方法 在pom文件中添加依赖
- Mysql学习总结(10)——MySql触发器使用讲解
触发器(TRIGGER)是由事件来触发某个操作.这些事件包括INSERT语句.UPDATE语句和DELETE语句.当数据库系统执行这些事件时,就会激活触发器执行相应的操作.MySQL从5.0.2版本开 ...
- 【Oracle】使用bbed恢复delete的数据
表中的数据被delete之后并不会真正删除数据,而是打了一个删除标记,仅仅要还没有被覆盖就能够恢复回来. 实验步骤例如以下: SYS@ORCL>create table bbed_test(x ...
- C++语言笔记系列之十三——派生类构造函数的调用
1.派生类构造函数的调用 (1)一个基类的全部数据成员均被派生类继承.创建一个派生类对象时.系统在为派生类对象分配单元时一定要为其基类数据成员分配子空间. (2)一个派生类对象在创建时不仅要调用派生类 ...
- [欧拉回路] poj 1386 Play on Words
题目链接: http://poj.org/problem?id=1386 Play on Words Time Limit: 1000MS Memory Limit: 10000K Total S ...
- C#中函数的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Docker+Jenkins持续集成
Docker+Jenkins持续集成 使用etcd+confd实现容器服务注册与发现 前面我们已经通过jenkins+docker搭建了基本的持续集成环境,实现了服务的自动构建和部署,但是,我们遇 ...
- MySql_Learn
1 id 自增长 auto_increment 2 获取当前时间 now() 3 新增字段 修改字段名称 简单分页功能 limit 10 offset 20; 查询第21到30条数据 selec ...
- 阿里云 django的一次web维护记录
首先, 丢给我一个阿里云的server的账号/password,之前没有玩过阿里云,想想应该也是ssh服务来远程登陆. 环境: centos+nginx+uwsgi+python2.7+django. ...
- stm32与arm7比较(经典)
http://wenku.baidu.com/link?url=LIVcT1AQL0IgVF1xan5Zy9rXarCBo66hj7OXSxM1ap7FpssO4c3sd1pZd8azfBPr3PBy ...