使用华丽丽的字体

所有的TextBlock等都用的默认字体,大家是否会感觉很千篇一律很枯燥呢?对于FontFamily,我们见过一些可以用的字体,但这个属性不像Foreground等有下拉框,所以我们在应用中见过的许多有意思的字体却没法用,因为不知道名字。

代码的话也贴张图示意一下吧。

好了,我就不再多说废话啦,名字都是从这里来的——>>>>>

注意:
1)除了微软雅黑外,大部分字体只能在Windows 8/8.1/10上体现出来,在WP8/8.1上无法发挥作用。这是因为这个字体库太大,微软没有放到手机上。

2)大部分中文字体可以作用在英文文本上,而英文字体则无法作用在中文文本上。(经验之谈,如果特例,请告知,谢谢。)

DatePickerFlyout等的使用

这一篇讲解在WP上DataPickerFlyout和TimePickerFlyout的使用,但它们只放在WP上哦,也正因此才将这一节放到最后一章的。

<Grid Background="Blue">  <Grid.RowDefinitions><RowDefinition Height="*"/><RowDefinition Height="*"/></Grid.RowDefinitions><StackPanel Grid.Row="0" Margin="12" Orientation="Vertical">     <Button Content="Let's Show DatePicker" ><Button.Flyout>        <DatePickerFlyout x:Name="datePickerFlyout" Title="选择日期" DatePicked="datePickerFlyout_DatePicked" Closed="datePickerFlyout_Closed" /></Button.Flyout></Button><DatePicker Header="Date"  Margin="4" />          <TextBlock Name="textBlockDate" FontSize="20" Margin="4" />            </StackPanel><StackPanel Grid.Row="1" Margin="12" Orientation="Vertical"><Button Content="Let's Show TimePicker" ><Button.Flyout><TimePickerFlyout x:Name="timePickerFlyout" Title="选择时间" TimePicked="timePickerFlyout_TimePicked" Closed="timePickerFlyout_Closed" /></Button.Flyout></Button><TimePicker Header="Time" Margin="4" /><TextBlock Name="textBlockTime" FontSize="20" Margin="4"/>             </StackPanel>
</Grid>

后台事件如下:

public sealed partial class MainPage : Page
{public MainPage(){this.InitializeComponent();this.NavigationCacheMode = NavigationCacheMode.Required;}protected override void OnNavigatedTo(NavigationEventArgs e){// 令天数加1datePickerFlyout.Date = DateTimeOffset.Now.AddDays(1);// 设置可选择的最大年份和最小年份datePickerFlyout.MinYear = DateTimeOffset.Now.AddYears(-100);   datePickerFlyout.MaxYear = DateTimeOffset.Now.AddYears(100);// 此处也可以令“年“、”月“、”日“中的某一个不显示datePickerFlyout.YearVisible = true;datePickerFlyout.MonthVisible = true;       datePickerFlyout.DayVisible = true;// 选择的历法// (Gregorian 公历, Hebrew 希伯来历, Hijri 回历, Japanese 日本历, Julian 罗马儒略历, Korean 朝鲜历, Taiwan 台湾历, Thai 泰国历, UmAlQura 古兰经历)datePickerFlyout.CalendarIdentifier = CalendarIdentifiers.Gregorian;                                                 // Time - TimePicker 控件当前显示的时间timePickerFlyout.Time = new TimeSpan(18, 0, 0);// 设置TimePickerFlyout的分钟选择框内数字的增幅timePickerFlyout.MinuteIncrement=2; //设置为24小时制,也可以为12小时制timePickerFlyout.ClockIdentifier = ClockIdentifiers.TwentyFourHour;                 }// 当用户点击DatePicker的完成按钮后激活该事件private void datePickerFlyout_DatePicked(DatePickerFlyout sender, DatePickedEventArgs args){                      textBlockDate.Text = args.NewDate.ToString("yyyy-MM-dd hh:mm:ss");textBlockDate.Text += Environment.NewLine;}// 当用户点击DatePicker的取消按钮或手机的返回按钮后激活该事件,当点击完成按钮后也将调用该事件private void datePickerFlyout_Closed(object sender, object e){textBlockDate.Text += "You just close the DatePickerFlyout.";textBlockDate.Text += Environment.NewLine;}// 当用户点击TimePicker的完成按钮后激活该事件private void timePickerFlyout_TimePicked(TimePickerFlyout sender, TimePickedEventArgs args){// e.OldTime - 原时间// e.NewTime - 新时间textBlockTime.Text = args.NewTime.ToString("c");textBlockTime.Text += Environment.NewLine;}// 当用户点击TimePicker的取消按钮或手机的返回按钮后激活该事件,当点击完成按钮后也将调用该事件private void timePickerFlyout_Closed(object sender, object e){textBlockTime.Text += "You just close the TimePickerFlyout.";textBlockTime.Text += Environment.NewLine;}
}

简单的讲,Flyout有两种创建方式,一种就是上面的通过Button的Flyout属性。另一种是通过FlyoutBase.AttachedFlyout属性给任何的FrameworkElement对象添加它。

关于FrameworkElement的更多知识,可以访问以下链接。

https://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.frameworkelement(v=vs.100).aspx

https://msdn.microsoft.com/en-us/library/system.windows.frameworkelement(v=vs.110).aspx

而Flyout则有6种不同的类型:Flyout、DatePickerFlyout、ListPickerFlyout、MenuFlyout、TimePickerFlyout。

时间紧迫就直接Show代码了。

XAML代码:

    <Page.Resources><Style TargetType="Button"><Setter Property="Margin" Value="12"/><Setter Property="FontSize" Value="20"/><Setter Property="Foreground"  Value="White"/><Setter Property="Background" Value="Green"/></Style></Page.Resources><Grid Background="Blue"><StackPanel Orientation="Vertical"><!-- Flyout --><Button Content="Let's Show Flyout"><Button.Flyout><Flyout><StackPanel ><TextBox PlaceholderText="What do you want to say?"/><Button HorizontalAlignment="Right" Content="Yup"/></StackPanel></Flyout></Button.Flyout></Button><!-- DatePickerFlyout --><Button Content="Let's Show DatePicker" HorizontalAlignment="Right"><Button.Flyout><DatePickerFlyout Title="You need to choose Date: "  DatePicked="DatePickerFlyout_DatePicked"/></Button.Flyout></Button><!-- ListPickerFlyout --><Button Content="Let's Show ListPicker" ><Button.Flyout><ListPickerFlyout x:Name="listPickerFlyout" Title="选择操作系统:" ItemsPicked="listPickerFlyout_ItemsPicked"  ><ListPickerFlyout.ItemTemplate><DataTemplate><TextBlock Text="{Binding}" FontSize="30"></TextBlock></DataTemplate></ListPickerFlyout.ItemTemplate></ListPickerFlyout></Button.Flyout></Button><!--  MenuFlyout --><Button x:Name="menuFlyoutButton" Content="Let's Show MenuFlyout" HorizontalAlignment="Right"><Button.Flyout ><MenuFlyout><MenuFlyoutItem Text="You just say yes?" Click="MenuFlyoutItem_Click"/><MenuFlyoutItem Text="You just say no?" Click="MenuFlyoutItem_Click"/><MenuFlyoutItem Text="You say nothing..." Click="MenuFlyoutItem_Click"/></MenuFlyout></Button.Flyout></Button><!--  PickerFlyout --><Button Content="Let's Show Picker" ><Button.Flyout><PickerFlyout  Confirmed="PickerFlyout_Confirmed" ConfirmationButtonsVisible="True"><TextBlock Text="Are you ok?" FontSize="30" Margin="0 100 0 0"/></PickerFlyout></Button.Flyout></Button><!-- TimePickerFlyout --><Button Content="Let's Show TimePicker" HorizontalAlignment="Right"><Button.Flyout><TimePickerFlyout Title="You need to choose Time: "  TimePicked="TimePickerFlyout_TimePicked"/></Button.Flyout></Button><!-- FlyoutBase --><TextBlock Text="Game Over" Margin="12" Foreground="Wheat" Tapped="TextBlock_Tapped" FontSize="20"><FlyoutBase.AttachedFlyout><Flyout><TextBox Text="哎哟,不错哦!"/></Flyout></FlyoutBase.AttachedFlyout></TextBlock></StackPanel></Grid>

后台C#代码:

    public sealed partial class MainPage : Page{public MainPage(){this.InitializeComponent();// 绑定List数据到ListPickerFlyoutlistPickerFlyout.ItemsSource = new List<string> { "Windows 10", "Windows 8/8.1", "Windows 7", "Windows Vista", "Windows XP","Others" };}// DatePickerFlyout的日期选中事件,此处事件内有是包含日期的MessageDialog控件private async void DatePickerFlyout_DatePicked(DatePickerFlyout sender, DatePickedEventArgs args){await new MessageDialog(args.NewDate.ToString()).ShowAsync();}// ListPickerFlyout的选中事件,选择列表中的一项后会以弹窗的方式显示出来private async void listPickerFlyout_ItemsPicked(ListPickerFlyout sender, ItemsPickedEventArgs args){if (sender.SelectedItem != null){await new MessageDialog("You choose: " + sender.SelectedItem.ToString()).ShowAsync();}}// MenuFlyout的菜单选项的点击事件,将选择的本文赋值给Contentprivate void MenuFlyoutItem_Click(object sender, RoutedEventArgs e){menuFlyoutButton.Content = (sender as MenuFlyoutItem).Text;}// PickerFlyout的确认事件,此处事件内有是包含字符串的MessageDialog控件private async void PickerFlyout_Confirmed(PickerFlyout sender, PickerConfirmedEventArgs args){await new MessageDialog("You choose ok").ShowAsync();}// TimePickerFlyout的时间选中事件,此处事件内有是包含所选时间的MessageDialog控件private async void TimePickerFlyout_TimePicked(TimePickerFlyout sender, TimePickedEventArgs args){await new MessageDialog(args.NewTime.ToString()).ShowAsync();}          // 通过FlyoutBase.ShowAttachedFlyout方法来展示出Flyout控件private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e){FrameworkElement element = sender as FrameworkElement;if (element != null){FlyoutBase.ShowAttachedFlyout(element);}}    }

好了代码就到这里了,来几张截图。

Windows App开发之更多技巧相关推荐

  1. Windows App开发之开发准备

    操作系统及SDK 操作系统 显而易见,想要开发Windows App就得在Windows 8/8.1/10上进行,老旧的Windows XP/Vista/7已经不能满足时代的需要了.当然,在Windo ...

  2. 【万里征程——Windows App开发】开发准备

    操作系统及SDK 操作系统 如果打算开发Windows App,那么你的电脑就不能再用老旧的Windows 7了.推荐使用Windows 8.1.写这篇博客的时候,我用的操作系统是Windows 10 ...

  3. 【万里征程——Windows App开发】应用栏

    基本的用法我们在 [万里征程--Windows App开发]页面布局和基本导航中已经讲过了,这里继续补充关于应用栏的更多用法. Icon 在之前的学习中,我们知道Icon属性中有很多很多系统预定义,但 ...

  4. 【万里征程——Windows App开发】SemanticZoom视图切换

    相信用过Windows Phone或者Windows 8/8.1/10的朋友对下面这张截图肯定不陌生.这就是通过SemanticZoom来实现的,当数据过多时,这种控件尤其适用.它有一个放大视图Zoo ...

  5. Windows App开发之文件与数据

    读取文件和文件夹名 这一节开始我们将陆续看到Windows App是怎样操作文件的. 在Windows上读取文件名.文件夹名 首先我们在XAML中定义一个Button和TextBlock,将读取文件/ ...

  6. Windows App开发之集成设置、帮助、搜索和共享

    应用设置和应用帮助 "设置"合约 上一节中我们学习了如何将应用设置保存到本地,这种方式是通过在App内添加设置选项,这里还有一种方式.微软将其称为"设置"合约, ...

  7. Windows App开发之集合控件与数据绑定

    为ListView和GridView添加数据 ListView采用垂直堆叠得方式显示数据,而GridView则采用水平堆叠得方式. 长相的话嘛,它们都差不多. <Grid Name=" ...

  8. Windows App开发之常用控件与应用栏

    控件的属性.事件与样式资源 如何添加控件 添加控件的方式有多种,大家更喜欢下面哪一种呢? 1)使用诸如Blend for Visual Studio或Microsoft Visual Studio X ...

  9. 【万里征程——Windows App开发】DatePickerFlyout、TimePickerFlyout的使用

    已经有挺长时间没有更新这个专栏了,不过刚才有网友私信问我一个问题现在就火速更新上一篇~ 这一篇讲解在WP上DataPickerFlyout和TimePickerFlyout的使用,但它们只能在WP上跑 ...

最新文章

  1. Jenkins部署Windows UI自动化的调度权限问题
  2. python selenium过极验滑动验证码
  3. python模块(一)
  4. mysql中查询一个字段属于哪一个数据库中的哪一个表的方式
  5. ios jenkins_如何使用Jenkins和Fastlane制作iOS点播构建系统
  6. Ceph块设备(RBD)常用命令
  7. java textarea 自动滚动条_月光软件站 - 编程文档 - Java - 如何实现滚动条的自动滚动到textarea的末尾...
  8. foremost命令参数中文说明
  9. DLL文件反编译(附:工具下载链接)
  10. C语言图形化界面——含图形、按钮、鼠标、进度条等部件制作(带详细代码、讲解及注释)
  11. 【转载】微信小程序中引入iconfont阿里矢量图库
  12. Android google中文开发网站
  13. 哈工大深圳计算机实验室介绍,实验室介绍
  14. 23种设计模式学习记录之单例设计模式
  15. Dell R720xd服务器装机暨改造过程
  16. 电子病历系统源码 winform 医院电子病历系统源码
  17. jvm原理与性能调优
  18. 一文读懂数据科学Notebook
  19. springboot中hibernate validator校验模式,分组校验,自定义校验
  20. 无与伦比的工业设计 iPhone 4详细评测

热门文章

  1. 关于zip包的一点小东西 暴力 字典 明文
  2. 编程小白从头学习ACM竞赛入门打卡 day 1
  3. matlab simu,MathWorks 发布 MATLAB 和 Simulink 版本 2021a
  4. android即刻夜间模式,【即刻热评】夜间模式:苹果和微信单选一,你选谁?
  5. 玩转Win7媒体中心 轻松看网络电视
  6. 有人通过这份面试题拿到了蚂蚁金服的offer!牛逼!
  7. Unity编程实战--牧师与魔鬼
  8. RISC-V架构的开源处理器分析
  9. 【监控仪表系统】Grafana 中文入门教程 | 构建你的第一个仪表盘
  10. ios10.x越狱后闪退