哎,只能说现在是越来越不行了,已经近一年没写C#的代码了,我居然隐隐有看不懂自己代码的趋势了,真伤!

我突然想起当年寒假里面为了,准备微软创新杯大赛所做的一些小应用,哈哈,于是我就拿出来显摆一下喽!

那个撒,模拟器我就不开了,直接有预览,textblock在文件启动时就会变为时间,默认的text属性我就没有去改它了(明明是自己懒!)

首先来看一下我们得MainPage.xaml文件:微软的开发工具绝对好啊,至少不用像安卓那样调试各种屏幕格式,,,,,

<phone:PhoneApplicationPage
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"
xmlns:es="clr-namespace:Microsoft.Expression.Shapes;assembly=Microsoft.Expression.Drawing"
x:Class="clock.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="timer">
<!--时钟的动画-->
<DoubleAnimation x:Name="sed" Storyboard.TargetProperty="Angle" Storyboard.TargetName="second" RepeatBehavior="Forever" Duration="0:1:0"> </DoubleAnimation> <DoubleAnimation x:Name="min" Storyboard.TargetProperty="Angle" Storyboard.TargetName="minute" RepeatBehavior="Forever" From="0" To="360" Duration="1:0:0" > </DoubleAnimation> <DoubleAnimation x:Name="hou" Storyboard.TargetProperty="Angle" Storyboard.TargetName="hour" RepeatBehavior="Forever" From="0" To="360" Duration="23:59:59"> </DoubleAnimation>
</Storyboard>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <!-- 本地化说明:
若要本地化显示的字符串,请将其值复制到应用程序的非特定语言资源文件(AppResources.resx)
中的适当命名的键,然后
将属性的引号之间的硬编码文本值
替换为其路径指向该字符串名称的绑定子句。 例如: Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" 此绑定指向模板的名为“ApplicationTitle”的字符串资源。 在“项目属性”选项卡中添加受支持的语言将会为
每种语言创建一个新的 resx 文件,该文件可以包含 UI 字符串的翻译值
。这些示例中的绑定将导致在运行时从
与应用程序的 CurrentUICulture 匹配的 .resx 文件中
提取属性的值。
--> <!--取消注释,以显示对齐网格,从而帮助确保
控件在公用边界上对齐。图像在系统栏中显示时的
上边距为 -32px。如果隐藏了系统栏,则将此值设为 0
(或完全删除边距)。 在发送之前删除此 XAML 和图像本身。-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
<!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="万能小应用" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="时间表" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel> <!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid Width="400" Height="400" Margin="28,120,28,87">
<Ellipse Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="400" Stroke="Black" VerticalAlignment="Top" Width="400"/>
<es:RegularPolygon Fill="#FF010111" HorizontalAlignment="Left" Height="200" InnerRadius="1" Margin="185,-1,0,201" PointCount="3" Stretch="Fill" Stroke="#FF010111" UseLayoutRounding="False" VerticalAlignment="Bottom" Width="30" RenderTransformOrigin="0.5,1" >
<es:RegularPolygon.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="second" CenterX="0" CenterY="0"> </RotateTransform>
</TransformGroup>
</es:RegularPolygon.RenderTransform>
</es:RegularPolygon>
<es:RegularPolygon Fill="#FFF11B11" HorizontalAlignment="Left" Height="150" InnerRadius="1" Margin="185,48,0,0" PointCount="3" Stretch="Fill" Stroke="#FFF11B11" UseLayoutRounding="False" VerticalAlignment="Top" Width="30" RenderTransformOrigin="0.5,1">
<es:RegularPolygon.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="minute" CenterX="0" CenterY="0"> </RotateTransform>
</TransformGroup>
</es:RegularPolygon.RenderTransform>
</es:RegularPolygon>
<es:RegularPolygon Fill="#FF1A1AF9" HorizontalAlignment="Left" Height="100" InnerRadius="1" Margin="185,98,0,0" PointCount="3" Stretch="Fill" Stroke="#FF1A1AF9" UseLayoutRounding="False" VerticalAlignment="Top" Width="30" RenderTransformOrigin="0.5,1">
<es:RegularPolygon.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="hour" CenterX="0" CenterY="0"> </RotateTransform>
</TransformGroup>
</es:RegularPolygon.RenderTransform>
</es:RegularPolygon>
</Grid>
<TextBlock Name="clock" HorizontalAlignment="Left" Margin="0,38,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" RenderTransformOrigin="0.22,0.674" Height="56" Width="446" FontSize="40"/>
</Grid> </Grid> </phone:PhoneApplicationPage>

完成布局之后呢,就是实现功能了!

定义一个var来获取当前时间,让秒钟,分钟,时钟指针都有自己相应的范围

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 clock.Resources;
using System.Windows.Threading; namespace clock
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
var time = DateTime.Now;
double hourAngle = ((float)time.Hour) / * + time.Minute / ;
double minuteAngle = ((float)time.Minute) / * + time.Second / ;
double secondAngle = ((float)time.Second) / * ;
InitializeComponent();
sed.From = secondAngle;
sed.To = secondAngle + ;
min.From = minuteAngle;
min.To = minuteAngle + ;
hou.From = hourAngle;
hou.To = hourAngle + ;
timer.Begin();
Intitimer();
// 用于本地化 ApplicationBar 的示例代码
//BuildLocalizedApplicationBar();
}
private void Intitimer()
{
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = new TimeSpan();
dt.Tick += dt_Tick;
dt.Start();
} private void dt_Tick(object sender, EventArgs e)
{
string second,str,minute,hour;
DateTime time = DateTime.Now;
int second1 = time.Second;
if (second1 < )
second = "" + second1.ToString();
else
second = second1.ToString();
int minute1 = time.Minute;
if (minute1 < )
minute = "" + minute1.ToString();
else
minute = minute1.ToString();
int hour1 = time.Hour;
if (hour1 < )
hour = "" + hour1.ToString();
else
hour= hour1.ToString();
str ="时间:"+ hour + ":" + minute + ":" + second;
clock.Text = str;
} //private void sed_Completed(object sender, EventArgs e)
//{ string second,str,minute,hour;
// DateTime time = DateTime.Now;
// sed1.
//} // 用于生成本地化 ApplicationBar 的示例代码
//private void BuildLocalizedApplicationBar()
//{
// // 将页面的 ApplicationBar 设置为 ApplicationBar 的新实例。
// ApplicationBar = new ApplicationBar(); // // 创建新按钮并将文本值设置为 AppResources 中的本地化字符串。
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton); // // 使用 AppResources 中的本地化字符串创建新菜单项。
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}
//我个人还是比较喜欢C#的风格的,java写的其实有点累,为何提醒键是alt+/  你要是直接用tab键多好啊!实现接口也只要: 而java 却要 implements(我小小地吐个嘈,大家不要介意嘛!)

最新文章

  1. HTML5本地存储
  2. linux内核分析作业:操作系统是如何工作的进行:完成一个简单的时间片轮转多道程序内核代码
  3. Intellij IDEA 配置最简单的maven-struts2环境的web项目
  4. JAVA网络编程
  5. 【转】 ip段/数字,如192.168.0.1/24是什么意思?
  6. .net发送邮件代码示例
  7. Red hat Linux(Centos 5/6)安装R语言
  8. android网络图片查看器
  9. 深入理解java虚拟机_第二章_读书笔记
  10. PHP秒杀系统-高并发高性能的极致挑战
  11. [转载]使用awk进行数字计算,保留指定位小数
  12. vue + BMap实现常用地图
  13. 微信h5,背景音乐自动播放
  14. Linux 搜某个文件里关键字的上下500行到执行文件里
  15. Json的序列化与反序列化以及乱入的k_BackingField
  16. Netsharp配置文件
  17. JVM 内存区域 (运行时数据区域)
  18. keybd_event使用方法
  19. 2018-2019-1 20189218《Linux内核原理与分析》第五周作业
  20. 【Java】JVM(六)虚拟机字节码执行引擎

热门文章

  1. JavaScript 对象属性
  2. pageadmin网站制作 怎么验证sql用户名和密码的正确性
  3. 375. 猜数字大小 II leetcode java
  4. Spring 中aop切面注解实现
  5. 网卡NAT方式下虚拟机安装FTP服务
  6. HTTP 缓存机制详解
  7. Ambiguous mapping found. Cannot map &#39;XXXController&#39; bean method
  8. Bootstrap Modal 关闭时右侧滚动条消失,页面左移的解决方法
  9. 静态网页、动态网页、apache和tomcat之间区别和联系
  10. php 判断两个时间段是否有交集