通过本例子学习:

  1. 如何使用自定义字体文件(.TTF)
  2. 如何播放声音
  3. 动画的使用
  4. Speech
  5. 设置闹铃
  6. 应用 设置 数据存储到IsolatedStorage
  • 如何使用自定义字体文件(.TTF)
<TextBlock x:Name="TimeBlock" HorizontalAlignment="Center"   

FontFamily="/AlarmClockWithVoice;component/Fonts/Fonts.zip#Quartz MS" 

Margin="89,272,87,256" FontSize="60">

字体文件BuildAction为Resource的使用方式:
(FontFamily="/AlarmClockWithVoice;component/Fonts/Fonts.zip#Quartz MS")
字体文件BuildAction为Content的使用方式:
(FontFamily="/Assets/Fonts/Fonts.zip#Quartz MS")

注意: Windows Phone 显示应用指定的 FontFamily 中的文本。如果字符不受 FontFamily 支持,或者应用未指定 FontFamily,Windows Phone 将基于字符和用于显示文本的框架元素的 xml:lang 选择一种字体。

  • 如何播放声音

以流的方式读取本地文件,并创建SoundEffect对象。

            StreamResourceInfo info = App.GetResourceStream(new Uri("Audio/alarm.wav", UriKind.Relative));
Microsoft.Xna.Framework.Audio.SoundEffect alarm = SoundEffect.FromStream(info.Stream);

播放,停止等操作,当前SoundEffect对象的状态SoundState 可以通过 属性State获取:

          this.alarmSound.Play();
}
else if (alarmSound.State == SoundState.Playing)
{
this.alarmSound.Stop();
}
}
else if (alarmSound.State == SoundState.Playing)
{
this.alarmSound.Stop();
}
  • 动画的使用

小时指针 图片的动画:

<Image x:Name="hourHand" HorizontalAlignment="Left" Height="20" Margin="255,203,0,0" 

Grid.Row="1" VerticalAlignment="Top" Width="99" Source="/Images/hourHand.jpg" 

RenderTransformOrigin="0.097,0.5">
<Image.RenderTransform>
<CompositeTransform ScaleX="1.5" ScaleY="1.5" TranslateX="-20.15"/>
</Image.RenderTransform>
</Image>

主要是通过“UIElement.RenderTransform”来实现的: public Transform RenderTransform { get; set; } 要使用多个动画效果,可以使用TransformGroup把多个动画包含其中。

7种变换分别是:

  1、TransLateTransForm 移动位置,包含水平移动和垂直移动

  2、ScaleTransform 缩放变换 对UI进行放大缩小 包含X轴上的缩放和Y轴上的缩放

  3、RotateTransform 旋转 根据定义的旋转点设置角度进行旋转

  4、SkewTransform 对UI进行一定角度的倾斜

  5、MatrixTransfrom 矩阵变换,一句标准矩阵表示的变换

  6、TransformGroup 复合变换按照指定顺序将多个变换复合为一个变换

  7、CompositeTransform 组合变换按照固定顺序组合一系列变换

  • Speech

语音命令:

1. 右键工程,新 添加 “语音命令项”

    <Command Name="alarmTimeSet">
<Example>Set alarm to 7:30 am.</Example>
<ListenFor>Set alarm to {hour} {minute} {ampm}</ListenFor>
<Feedback>Setting the alarm clock</Feedback>
<Navigate Target="MainPage.xaml"/>
</Command> <PhraseList Label="hour">
<Item>1</Item>
<Item>2</Item>
<Item>3</Item>
<Item>4</Item>
<Item>5</Item>
<Item>6</Item>
<Item>7</Item>
<Item>8</Item>
<Item>9</Item>
<Item>10</Item>
<Item>11</Item>
<Item>12</Item>
</PhraseList>

2. 初始化语音命令:

                    Uri uri = new Uri("ms-appx:///voicecommands.xml", UriKind.Absolute);
await Windows.Phone.Speech.VoiceCommands.VoiceCommandService.InstallCommandSetsFromFileAsync(uri);

语音识别读取:

1. 初始化语音识别相关属性:

using Windows.Phone.Speech.Recognition;
using Windows.Phone.Speech.Synthesis; Speech.recognizer = new SpeechRecognizer();
Speech.synthesizer = new SpeechSynthesizer();
Speech.recognizerUI = new SpeechRecognizerUI(); // Sets the en-US male voice.
IEnumerable<VoiceInformation> enUSMaleVoices = from voice in InstalledVoices.All
where voice.Gender == VoiceGender.Male
&& voice.Language == "en-US"
select voice; Speech.synthesizer.SetVoice(enUSMaleVoices.ElementAt());

2. 朗读文本:

                        await Speech.synthesizer.SpeakTextAsync("Alarm is now set for "
+ Settings.alarmTime.Value.Hours + " " + Settings.alarmTime.Value.Minutes);
  • 设置闹铃

1. 初始化设置闹钟:

using Microsoft.Phone.Scheduler;

public static Alarm alarm;

            Clock.alarm = new Alarm("alarm");
Clock.alarm.ExpirationTime = DateTime.MaxValue;
Clock.alarm.RecurrenceType = RecurrenceInterval.Daily;
Clock.alarm.Sound = new Uri("Audio/alarm.wav", UriKind.Relative);
Clock.alarm.Content = "Alarm ringing!";

2. 添加到SchduleActionService,一个专门用于管理计划任务的类:

ScheduledActionService.Add(Clock.alarm);

3.根据用户操作输入,设定时间:
参数为 年月日时分秒, 1 表示everyday。

Clock.alarm.BeginTime = new DateTime(, , , hours, minutes, );
  • 应用 设置 数据存储到IsolatedStorage
using System.IO.IsolatedStorage;

public class StoredItem<T>
{
private T value;
private T defaultValue;
private string name;
private bool needRefresh; public StoredItem(string _name, T _defaultValue)
{
this.name = _name;
this.defaultValue = _defaultValue; // If isolated storage doesn't have the value stored yet
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue(this.name, out this.value))
{
this.value = _defaultValue;
IsolatedStorageSettings.ApplicationSettings[this.name] = _defaultValue;
} this.needRefresh = false;
} public T Value
{
get
{
if (this.needRefresh)
{
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue(this.name, out this.value))
{
IsolatedStorageSettings.ApplicationSettings[this.name] = this.defaultValue;
this.value = this.defaultValue;
}
this.needRefresh = false;
} return this.value;
}
set
{
if (this.value.Equals(value))
return; // Store the value in isolated storage.
IsolatedStorageSettings.ApplicationSettings[this.name] = value;
this.needRefresh = true;
}
} public T DefaultValue
{
get
{
return this.defaultValue;
}
} public string Name
{
get
{
return this.name;
}
} public override string ToString()
{
return this.name
+ " with value: " + this.value.ToString()
+ ", default value: " + this.defaultValue.ToString();
} public void ForceRefresh()
{
this.needRefresh = true;
}
}

例子:Alarm Clock with voice Commands Sample的更多相关文章

  1. Centos 6.5 安装 chrome , mplayer , alarm , clock

    http://my.oschina.net/jianweizhang/blog/306946 Chrome wget http://chrome.richardlloyd.org.uk/install ...

  2. Codeforces Round #451 (Div. 2) [ D. Alarm Clock ] [ E. Squares and not squares ] [ F. Restoring the Expression ]

    PROBLEM D. Alarm Clock 题 OvO http://codeforces.com/contest/898/problem/D codeforces 898d 解 从前往后枚举,放进 ...

  3. 例子:Bluetooth app to device sample

    本例子演示了: 判断蓝牙是否打开,是通过一个HRsult值为0x8007048F的异常来判断的 catch (Exception ex) { if ((uint)ex.HResult == 0x800 ...

  4. Voice Commands (VCD) Cortana 微软小娜示例

    Cortana 样品 您可以创建自定义功能Cortana使用Cortana技能装备或遗留的声音命令(VCD)平台. 在这里,你可以找到相关的样品: Cortana技能装备 目前Cortana技巧是建立 ...

  5. Gym 100531A Alarm Clock (水题)

    题意:给定一个被高亮的数,问你是不是有个时间恰好高亮是这个数. 析:直接暴力,直接暴力,枚举每一位时间,当然也可以枚举时间,能找到就是有,找不到就算了. 代码如下: #pragma comment(l ...

  6. 【Codeforces Round #451 (Div. 2) D】Alarm Clock

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...

  7. 【HDOJ】2395 Alarm Clock

    水题. /* 2395 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...

  8. Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)

    A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. cf898d Alarm Clock

    区间上有 \(n\) 个点,问你为达到目的:长度为 \(m\) 的区间内点的个数都 $ < k$需要去掉多少个点. 贪心.每个区间我们总是去掉最后的,也就是说除非万不得已我们是不会去掉点的. 队 ...

随机推荐

  1. Mvc请求管道中的19个事件

    下面是请求管道中的19个事件. (1)BeginRequest: 开始处理请求 (2)AuthenticateRequest授权验证请求,获取用户授权信息 (3):PostAuthenticateRe ...

  2. UBI系统原理-中【转】

    转自:http://blog.chinaunix.net/uid-28236237-id-4217118.html UBI 文件头位置 EC头都放置在擦除块的开始偏移位置,占用64字节空间.之后防止V ...

  3. ReentrantReadWriteLock类和ReentrantLock类的区别

    Java.util.concurrent.locks包定义了两个锁类,ReentrantLock和ReentrantReadWriteLock类. 当有很多线程都从某个数据结构中读取数据而很少有线程对 ...

  4. oracle 卸载

    由于工作需要,重装了一下Oracle,然后发现同SQLServer,MySQL等数据库相比,Oracle的卸载重装真是不一般的麻烦.     整理了一下我的Oracle的卸载重装过程,给自己备忘,同时 ...

  5. LA 3523 圆桌骑士

    题目链接:http://vjudge.net/contest/141787#problem/A http://poj.org/problem?id=2942 此题很经典 知识点:DFS染色,点-双连通 ...

  6. 【前端】String.prototype.match() 用法详解

    var str="1 plus 2 equal 3" // 正则表达式 console.log(str.match(/\d+/g)); // ["1", &qu ...

  7. 【WEB】HTTP协议

    http1.0和http1.1 区别,http1.1可以发送多个http请求

  8. AngularJS事件绑定的使用详解

    本文和大家分享的主要是AngularJS中事件绑定相关知识点,希望通过本文的分享,对大家学习和使用AngularJS有所帮助. 1.绑定事件:表达式.事件方法名: 2.绑定点击事件实例:显示.隐藏页面 ...

  9. Git最佳实践

    1.git init 2.git add. 3.git add README.md 4.git commit -m "init" 5.git remote add origin h ...

  10. Windows C++ 子目录数量

    CFileFind OneFile; BOOL bWorking = FALSE; ; ) != "\\") { strPath += "\\*.*"; } b ...