哎,只能说现在是越来越不行了,已经近一年没写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(我小小地吐个嘈,大家不要介意嘛!)

WP的万能小应用时钟表的更多相关文章

  1. 在做关于NIO TCP编程小案例时遇到无法监听write的问题,没想到只是我的if语句的位置放错了位置,哎,看了半天没看出来

    在做关于NIO TCP编程小案例时遇到无法监听write的问题,没想到只是我的if语句的位置放错了位置,哎,看了半天没看出来 贴下课堂笔记: 在Java中使用NIO进行网络TCP套接字编程主要以下几个 ...

  2. jquery+html5制作超酷的圆盘时钟表

    自己封装的一个用HTML5+jQuery写的时钟表 代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...

  3. FFMpeg笔记(五) 录制小视频时几个问题解决

    1. YUV数据在使用avfilter scale时在特定的分辨率下UV分量不对 由于是小视频,那么分辨率不需要太高,但是有的视频源是1080p,甚至有的是4K的,所以对视频源进行scale非常有必要 ...

  4. C++写时钟表

    time函数的运用,输出是没输换行,在流中,就什么的输不出,可以用清流函数,fflush(stdout) 代码 #include<iostream>#include<cstdio&g ...

  5. webpack打包小图片时进行Base64转码

    关于base64 优点: base64就是一串字符串码表示的图片,在加载页面和js时一块加载出来,减少了加载图片时的http请求.加载一张图片时会发起一次http请求,http请求每次建立都会需要一定 ...

  6. 【短道速滑一】OpenCV中cvResize函数使用双线性插值缩小图像到长宽大小一半时速度飞快(比最近邻还快)之异象解析和自我实现。

    今天,一个朋友想使用我的SSE优化Demo里的双线性插值算法,他已经在项目里使用了OpenCV,因此,我就建议他直接使用OpenCV,朋友的程序非常注意效率和实时性(因为是处理视频),因此希望我能测试 ...

  7. 通过jQuery制作电子时钟表的代码

    源码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <titl ...

  8. 小程序input输入框获取焦点时,文字会出现闪动

    最近在开发小程序时,发现一个有趣的现象.input里面设置了placeholder,随后当输入框获取焦点时,文字会出现一瞬间的抖动,随后正常. 猜想可能是设置的font-family不同引起的抖动,但 ...

  9. 关于小程序登录时获取openId和unionId走过的坑

    目前的项目是在做小程序这方面的,接触过的人应该都知道,同一个微信开放平台下的相同主体的App.公众号.小程序的unionid是相同的,这样就可以锁定是不是同一个用户.微信针对不同的用户在不同的应用下都 ...

随机推荐

  1. div自适应宽度

    对于div自适应宽度,网上的说法基本上都是将要自适应宽度的div放在其它固定宽度的最后,不指定其float属性或将float属性指定为none,比如三栏布局居中的一栏为自适应宽度,就可以这样来定义三栏 ...

  2. daylyknowledge1

    1.数据库截取字符串:toFixed():四舍五入substring(cp_introduce,0,11) cp_introduce前台截取: field: 'an_content', title: ...

  3. 【12c OCP】最新CUUG OCP-071考试题库(51题)

    ------------------------------------------------------- 51.(12-10)choose the best answer: Evaluate t ...

  4. Spring框架注解

    这四个注解,功能都是一样的,都是用来创建对象的. 但是为什么有这么四个吗?Spring中提供了三个@Component的衍生注解:(功能目前来讲是一样的) @Controller      :WEB层 ...

  5. jenkins+gitlab+robot framework 中遇到的坑

    问题一:拉Git源代码时提示无权限 原来之前用的ssh密钥一直都是自己的用户生成的.其实在Jenkins系统使用的都是Jenkins这个系统帐号的. 解决方法: 切换到jenkins这个帐号下生成个新 ...

  6. sqli-labs lession 5 之盲注型SQL入门

    本文作者:Mochazz 如果所查询的用户id在数据库中,可以发现页面显示”You are in”,而不像前4关那样会显示出具体的账号密码. 如果sql语句查询结果不存在,则不会显示”You are ...

  7. 代码审计之Catfish CMS v4.5.7后台作者权限越权两枚+存储型XSS一枚

    首先本地搭建环境,我所使用的是Windows PHPstudy集成环境.使用起来非常方便.特别是审计的时候.可以任意切换PHP版本. 本文作者:226safe Team – Poacher 0×01 ...

  8. [HTML] <meta name="viewport" content="width=device-width,initial-scale=1.0">释义

    <meta name="viewport" content="width=device-width,initial-scale=1.0">这是 HT ...

  9. 记一名软件实施自学转Java开发,附学习计划

    2015年毕业到现在已经3年了,而我转型开发已经有一年的时间了.写这篇文章除了记录,主要还是想分享一些经历给想要转型开发的同学们,不要走那些我走过的弯路. 2015年入职了第一家公司,当时是做的分销系 ...

  10. .NET Core容器化之多容器应用部署-使用Docker-Compose

    原文补充: -- docker-compose.ymlversion: ' services: mvc-web: container_name: mvc.web.compose build: . re ...