博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows App开发之更多技巧
阅读量:7082 次
发布时间:2019-06-28

本文共 6925 字,大约阅读时间需要 23 分钟。

使用华丽丽的字体

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

这里写图片描述

这里写图片描述

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

这里写图片描述

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

这里写图片描述

注意:

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

这里写图片描述

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

DatePickerFlyout等的使用

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

后台事件如下:

public sealed partial class MainPage : Page{    public MainPage()    {        this.InitializeComponent();        this.NavigationCacheMode = NavigationCacheMode.Required;    }    protected override void OnNavigatedTo(NavigationEventArgs e)    {        // 令天数加1        datePickerFlyout.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的更多知识,可以访问以下链接。

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

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

XAML代码:

后台C#代码:

public sealed partial class MainPage : Page    {        public MainPage()        {            this.InitializeComponent();            // 绑定List数据到ListPickerFlyout            listPickerFlyout.ItemsSource = new List
{ "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的菜单选项的点击事件,将选择的本文赋值给Content private 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); } } }

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

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

转载于:https://www.cnblogs.com/NoMasp/p/4785977.html

你可能感兴趣的文章
求模版函数地址
查看>>
使用 Apache POI 处理 Microsoft Office 文档
查看>>
10个实用的但偏执的Java编程技术
查看>>
bash批量创建目录
查看>>
Windows pscp
查看>>
初学Python的学习笔记8----面向对象、数据封装、访问限制、继承和多态
查看>>
CAS注销后自定义跳转路径
查看>>
[大数据量]布隆过滤器(Bloom Filter)适用类型以及具体示例
查看>>
Linux | OOM机制的理解
查看>>
linux启动nagios无法通过web访问解决
查看>>
OpenSessionInViewFilter原理以及为什么要用OpenSessionInViewFilter
查看>>
决策树
查看>>
微服务实战(六):选择微服务部署策略
查看>>
mybatis入门教程(二)
查看>>
Java NIO(一)
查看>>
UIWebView类的调用
查看>>
MongoVE连接MongoDB 不显示数据问题
查看>>
npm 更新模块
查看>>
PhalApi 2.4.2 - 接口,从简单开始!(为了更好的接口开发体验,2019重新出发)...
查看>>
Docker介绍
查看>>