如果你已经开始了 Windows Phone 8.1 的学习,就会发现许多在 8.0 下的控件在 8.1 中都发生了变化,以下就谈谈几个 8.1 下的新控件以及与 8.0 控件的改变。

1. TextBox, AutoSuggestBox

TextBox 终于有了 Header 属性,再也不用为 TextBox 写一堆 TextBlock 了。

<TextBox Header="TextBoxWithHeader"/>

当某些控件没有 Header 属性的时候,可以将 TextBlock 的 Style 绑定为 ControlHeaderTextBlockStyle,这样就可以与 TextBox 的 Header 样式相同了。

<TextBlock Text="TextBoxWithoutHeader" Style="{StaticResource ControlHeaderTextBlockStyle}"/>
<RadioButton Content="RadioButton"/>

界面为这样:

AutoSuggestBox 的使用则只需绑定 ItemsSource。

XAML:

<AutoSuggestBox x:Name="autoBox"
Header="AutoSuggestBox"
GotFocus="autoBox_GotFocus"
TextChanged="autoBox_TextChanged">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>

C#:

List<string> suggestions = new List<string>(){ "S1", "S2", "S3", "U1", "U2", "U3" };

private void autoBox_GotFocus(object sender, RoutedEventArgs e)
{
autoBox.ItemsSource = suggestions;
} private void autoBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
string filter = sender.Text.ToUpper();
autoBox.ItemsSource = suggestions.Where(s => s.ToUpper().Contains(filter));
}

界面为这样:

2. MessageDialog, ContentDialog

刚学 8.1 遇到的第一个问题就是 MessageBox 不见了,其实它只是换成了 MessageDialog。

private async void messageDialogButton_Click(object sender, RoutedEventArgs e)
{
MessageDialog messageDialog = new MessageDialog("MessageBox --> MessageDialog", "MessageDialog");
await messageDialog.ShowAsync();
}

界面:

ContentDialog 则可以设置为部分或者全屏,或者直接在项目里新建一个 ContentDialog。

private async void partialDialogButton_Click(object sender, RoutedEventArgs e)
{
ContentDialog contentDialog = new ContentDialog();
contentDialog.FullSizeDesired = false;
contentDialog.Title = "Partial ContentDialog";
contentDialog.Content = "Partial";
await contentDialog.ShowAsync();
} private async void fullDialogButton_Click(object sender, RoutedEventArgs e)
{
ContentDialog contentDialog = new ContentDialog();
contentDialog.FullSizeDesired = true;
contentDialog.Title = "Full ContentDialog";
contentDialog.Content = "Full";
await contentDialog.ShowAsync();
} private async void customDialogButton_Click(object sender, RoutedEventArgs e)
{
CustomDialog customDialog = new CustomDialog();
await customDialog.ShowAsync();
}

界面:

Dialog 的显示都为异步方法。

3. Button

Button.Flyout.Flyout

<Button Content="Button.Flyout.Flyout"
HorizontalAlignment="Center">
<Button.Flyout>
<Flyout>
<StackPanel HorizontalAlignment="Center">
<TextBlock Text="Button.Flyout"
FontSize="40"/>
<Button Content="OK"
HorizontalAlignment="Center"/>
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>

界面:

Button.Flyout.MenuFlyout

<Button Content="Button.Flyout.MenuFlyout"
HorizontalAlignment="Center">
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="MenuFlyoutItem"/>
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem"/>
</MenuFlyout>
</Button.Flyout>
</Button>

界面:

4. BottomAppBar

之前的 ApplicationBar 更换成了 BottomAppBar。

<Page.BottomAppBar>
<CommandBar>
<CommandBar.PrimaryCommands>
<AppBarButton Icon="Accept" Label="Accept"/>
<AppBarButton Icon="Cancel" Label="Cancel"/>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Help" Label="Help"/>
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.BottomAppBar>

界面:

还有就是 AppBarButton 同样支持 Flyout。

5. StatusBar

之前的 SystemTray 更改为 StatusBar,并且只能通过 C# 代码控制,不能用 XAML 控制。

private async void Button_Click(object sender, RoutedEventArgs e)
{
Windows.UI.ViewManagement.StatusBar statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
await statusBar.HideAsync();
}

界面:

6. Magic Number:10

在 8.0 时代,Magic Number 为 12,也就是间距最好都设为 12 的倍数,或者 6。

但到了 8.1,微软将 12 改成了 10。

Windows Phone 8.1 控件的更多相关文章

  1. [深入浅出Windows 10]分屏控件(SplitView)

    4.18 分屏控件(SplitView) 分屏控件(SplitView)是Windows 10新增的控件类型,也是Windows 10通用应用程序主推的交互控件,通常和一个汉堡按钮搭配作为一种抽屉式菜 ...

  2. 深入Windows窗体原理及控件重绘技巧

    之前有学MFC的同学告诉我觉得Windows的控件重绘难以理解,就算重绘成功了还是有些地方不明白,我觉得可能很多人都有这样的问题,在这里我从Windows窗体的最基本原理来讲解,如果你有类似的疑惑希望 ...

  3. Windows phone 自定义用户控件(UserControl)——ColorPicker

    编码前 学习Windows phone自定义用户控件,在<WPF编程宝典>学习的小例子.并根据windows phone稍微的不同,做了点修改.ColorPicker(颜色拾取器):拥有三 ...

  4. Windows Phone - 按钮/button 控件

    System.Windows.Controls.Button   button控件一.button控件的各种样式的展示可以通过 …… 来给控件定义公共的样式调用样式的方法:在Button控件上添加样式 ...

  5. windows下注册ocx控件

    OCX 是对象类别扩充组件(Object Linking and Embedding (OLE) Control Extension):是可执行的文件的一种,但不可直接被执行: 是 ocx 控件的扩展 ...

  6. Windows高DPI系列控件(二) - 柱状图

    目录 一.QCP 二.效果展示 三.高DPI适配 1.自定义柱状图 2.新的柱状图 3.测试代码 四.相关文章 原文链接:Windows高DPI系列控件(二) - 柱状图 一.QCP QCP全称QCu ...

  7. 【Windows编程】系列第二篇:Windows SDK创建基本控件

    在Win32 SDK环境下,怎么来创建常用的那些基本控件呢?我们知道如果用MFC,简单的拖放即可完成大多数控件的创建,但是我们既然是用Windows SDK API编程,当然是从根上解决这个问题,实际 ...

  8. Windows Phone 四、控件模版

    控件模版的概念 Windows Phone中每一个控件都有一个默认的模版,用于描述控件的内部组成结构和外观样式 相对于原本的样式外观操作,自定义模版的可自定义性更强 最基本的重写控件模版 <Gr ...

  9. Windows 8.1 新增控件之 Hyperlink

    Hyperlink 控件应该不用过多介绍大家肯定十分清楚其作用,它的功能就像HTML中的<a href="">标签一样,只不过是在XAML中实现. 使用Hyperlin ...

  10. Windows 8.1 新增控件之 TimePicker

    之前已经为大家介绍过DatePicker 控件的相关内容,有日期控件当然就得有时间控件,本篇将和各位一起了解TimePicker 的使用方法. 先来介绍一下ClockIdentifier 属性,默认情 ...

随机推荐

  1. Django快速搭建博客

    准备工作: 1.Python 2.Django 3.Git 安装Python: 官网下载 安装Django: #安装最新版本的Django $ pip install django #或者指定安装版本 ...

  2. vector转数组

    vector转数组 由于vector内部的数据是存放在连续的存储空间,vector转数组事实上只需要获取vector中第一个数据的地址和数据的长度即可.如果仅仅是传参,无需任何操作,直接传地址即可,如 ...

  3. [1,2,3].forEach(alert);这样的写法有什么利和弊吗?

    以下这个问题遇到了之后.问了太阳神,以下是太阳神的解答: [1,2,3].forEach(alert);这样的写法有什么利和弊吗? 首先forEach使用方法非常easy降低代码量, 可是也有非常多地 ...

  4. ie为什么那么垃圾(不是ie垃圾,是ie用的人太多了,很多在用低版本)

    ie为什么那么垃圾(不是ie垃圾,是ie用的人太多了,很多在用低版本) 一.总结 1.我们觉得ie差的原因:我们拿老的ie和最新的其它浏览器做比较了,两者相差了很多年.比较微软几十年才发布了11个ie ...

  5. matlab 辅助函数 —— 文件下载与文件解压

    0. 可读性的提升 为了提升代码的交互友好性,可在代码执行一些耗时操作时,显示地输出一些文本信息,以显示进度: fprintf('Downloading xxfilename...\n') urlwr ...

  6. ORACLE11g R2【RAC+ASM→RAC+ASM】

    ORACLE11g R2[RAC+ASM→RAC+ASM] 本演示案例所用环境:RAC+ASM+OMF   primary standby OS Hostname node1,node2 dgnode ...

  7. GIT,SVN,CVS的区别比较

    Git .CVS.SVN比较 项目源代码的版本管理工具中,比较常用的主要有:CVS.SVN.Git 和 Mercurial  (其中,关于SVN,请参见博客:SVN常用命令 和 SVN服务器配置) 目 ...

  8. 洛谷—— P2234 [HNOI2002]营业额统计

    https://www.luogu.org/problem/show?pid=2234 题目描述 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业 ...

  9. android--显式跳转和隐式跳转的差别使用方法

    #创建第二个activity * 新创建的activity.必须在清单文件里做配置,否则系统找不到,在显示时会直接报错 <activity android:name="com.ithe ...

  10. Day2:PYC

    一.pyc里装的是预编译后的字节码文件 二.一般存放在”__pycache__“目录 三.当python程序运行时,编译的结果是保存在位于内存中的PyCodeObject中,当Python程序运行结 ...