如果你已经开始了 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. Android线程间通讯的几种方式

    1.runOnUiThread(Runnable)              在子线程中直接使用该方法,可以更新UI runOnUiThread(new Runnable(){//更新UI       ...

  2. 九度OJ—题目1032:ZOJ

    题目描写叙述: 读入一个字符串.字符串中包括ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出.当某个字符用完时,剩下的仍然依照ZOJ的顺序输出. 输入: 题目包括多组用例,每组用例占一行,包括ZOJ ...

  3. 地图上显示div点位

    功能核心:  地理坐标转屏幕坐标 用到的插件:jquery  animo动画插件 核心代码: var point = new Point(lon, lat, map.spatialReference) ...

  4. 让ie6 7 8 9支持原生html5 websocket

      让ie6 7 8 9支持原生html5 websocket   从github上的 web-socket-js(socket.io好像也是用这个做的他们的flash替代传输方式)改过来的.不过值得 ...

  5. 8.spring-boot配置log4j

    转自:https://www.cnblogs.com/qixing/p/7763582.html <dependency> <groupId>org.springframewo ...

  6. C/S与B/S架构比较

    一C/S 1.C/S概念 C/S是Client/Server的缩写.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.Informix或 SQL Serv ...

  7. Intent传递对象的几种方式

    原创文章.转载请注明 http://blog.csdn.net/leejizhou/article/details/51105060 李济洲的博客 Intent的使用方法相信你已经比較熟悉了,Inte ...

  8. Swiper+ ejs模板引擎+ iScroll插件知识总结

    一. Swiper swiper是一个应用于移动端的动画插件,原理类似于轮播图 官网 http://www.swiper.com.cn/# html结构 <div class="swi ...

  9. 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...

  10. [React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber

    Using a react-intl FormattedNumber component, we'll pass a Number and a few additional props in orde ...