原文出自:http://www.bcmeng.com/contentdialog/

在应用开发中我们必不可少的会使用到消息框,windows phone8中的messagebox在windows phone8.1中变成了MessageDialog.使用方法大体相差不大.不过MessageDialog的功能过于简单,许多时候无法满足我们的实际需要.在windows phone 8.1中出现了ContentDialog,ContentDialog不仅可以选择半屏或者全屏展示,里面的内容还可以像一个XAML页面一样实现自定义.
下面我们通过代码和实际运行效果来看一下:

ContentDialog半屏:

private  async void Button_Click(object sender, RoutedEventArgs e)//半屏
{
ContentDialog dialog = new ContentDialog()
{
Title = "Download updates?", //标题
Content = "This update will clean the slate for Iron Man",//内容
FullSizeDesired=false, //是否全屏展示
PrimaryButtonText = "Yes, clean it",//第一个按钮内容
SecondaryButtonText = "No, Dont!"
};
dialog.SecondaryButtonClick += dialog_SecondaryButtonClick;//第二个按钮单击事件
dialog.PrimaryButtonClick += dialog_PrimaryButtonClick; ContentDialogResult result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary) { } //处理第一个按钮的返回
else if (result == ContentDialogResult.Secondary) { }//处理第二个按钮的返回 } async void dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
await new MessageDialog("您选择了第一个按钮").ShowAsync();
} async void dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
await new MessageDialog("您选择了第二个按钮").ShowAsync();
}

ContentDialog全屏:

private async void Button_Click_1(object sender, RoutedEventArgs e)//全屏
{
ContentDialog contentdialog = new ContentDialog();
contentdialog.Title = "编程小梦";
contentdialog.Content = "专注于windows phone应用开发";
contentdialog.PrimaryButtonText = "赞一个";
contentdialog.SecondaryButtonText = "顶一个";
contentdialog.FullSizeDesired = true;
await contentdialog.ShowAsync();
}

ContentDialog自定义1:

<ContentDialog
x:Class="ContentDialogDemo.ContentDialog1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ContentDialogDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="DIALOG TITLE"
PrimaryButtonText="sign in"
SecondaryButtonText="cancel"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"> <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBox Name="email" Header="Email address"/>
<PasswordBox Name="password" Header="Password"/>
<CheckBox Name="showPassword" Content="Show password"/> <!-- 内容主体 -->
<TextBlock Name="body" Style="{StaticResource MessageDialogContentStyle}" TextWrapping="Wrap">
<TextBlock.Text>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ContentDialog>

调用方法:

ContentDialog1 contentDialog1 = new ContentDialog1(); //ContentDialog1是系统自带的内容对话框页面
await contentDialog1.ShowAsync();

ContentDialog自定义2:

<ContentDialog
x:Class="ContentDialogDemo.ContentDialog2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ContentDialogDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="小梦词典"
PrimaryButtonText="关于"
SecondaryButtonText="好评"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
<Grid >
<GridView HorizontalAlignment="Center"> <GridViewItem Margin="">
<Button Content="查词" Background="#FFC5246D"
></Button>
</GridViewItem>
<GridViewItem Margin="">
<Button Content="翻译" Background="#FFEAC418"
Name="translate" ></Button>
</GridViewItem>
<GridViewItem Margin="">
<Button Content="生词" Background="#FFCB32DA"
></Button>
</GridViewItem>
<GridViewItem Margin="">
<Button Content="关于" Background="#FF58E4B5"
></Button>
</GridViewItem>
</GridView>
</Grid>
</ContentDialog>

调用方法和上面一样,最终运行效果如下:

windows phone 8.1开发:(消息弹出框)强大的ContentDialog的更多相关文章

  1. 移动web:Tips消息弹出框

    在web开发中经常会用到像alert这样的弹出消息,每个浏览器自带的消息弹出框都不相同.为了统一外观,实现自定义的功能,动手写一个弹出框插件. 对弹出框的实现要求如下: 1. 仿照IOS系统弹出外观 ...

  2. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...

  3. MessageBox页面消息弹出框类

    MessageBox页面消息弹出框类: public class MessageBox { /// <summary> /// 自定义弹出窗口内容,不跳转 /// </summary ...

  4. WPF实战之一 桌面消息框(右下角消息弹出框)

    此版本是根据别人的项目改造的,记录下笔记 原文:https://blog.csdn.net/catshitone/article/details/75089069 一.即时弹出 1.创建弹出框 新建一 ...

  5. Easyui-交互式消息弹出框

    由于项目在优化的时候需要用到弹出框,按自己的想法是傻傻的用一些alert直接弹出得了,但是这样用户体验度不是特别好,影响界面美观,所以自己还是用了封装好的easyui给的消息框,怎么用呢,这个里面很有 ...

  6. Js:消息弹出框、获取时间区间、时间格式、easyui datebox 自定义校验、表单数据转化json、控制两个日期不能只填一个

    (function ($) { $.messageBox = function (message) { $.messager.show({ title:'消息框提示', msg:message, sh ...

  7. Android 开发笔记 “弹出框”

    AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this); builder.setMessage("Are y ...

  8. android开发学习 ------- 弹出框

    这是一种方法,是我觉得简单易懂代码量较少的一种: /* 创建AlertDialog对象并显示 */ final AlertDialog alertDialog = new AlertDialog.Bu ...

  9. Windows Phone 几种弹出框提示方式

    首先,我们需要在网络上下载一个Coding4Fun 然后,引用  using Coding4Fun.Phone.Controls.Toolkit;                using Codin ...

随机推荐

  1. linux脚本错误: line *: [: missing `]'

    错误: line *: [: missing `]' 写脚本时,我碰到这个问题是因为if [ ]; ...else...fi语句 解决方法: if后面的[] (test) 和条件要有空格,如: 对于语 ...

  2. linux 中用python实现终端命令行命令

    在python代码中实现和在终端中输入的命令行一样的效果,以命令(audacious -p &)为例,该代码实现用audacious在后台播放音乐的功能,当然前提是安装了audacious. ...

  3. 微信前端面试题----js实现LazyMan

    这是微信小程序的一道面试题,题目是这样的: 实现一个LazyMan,可以按照以下方式调用:LazyMan("Hank")输出:Hi! This is Hank! LazyMan(& ...

  4. 《JAVASCRIPT高级程序设计》第一章

    在使用调制解调器的时代,频繁的表单验证对客户端来说是一个很大的负担,javascript,作为一种专门进行表单验证的客户端脚本语言诞生了.到今天,javascript早已超越了当初设定的角色.Java ...

  5. [html5] 学习笔记-改良的input元素种类

    在html5中,大幅度增加与改良了input元素的种类,可以简单的使用这些元素来实现之前需要JS脚本来实现的功能. 1.url类型.email类型.date类型.time类型.datetime类型.d ...

  6. webpack入门+react环境配置

    小结放在前:这篇文章主要是为下一篇的react提前铺好路,webpack是一个前端资源模块化管理和打包工具,说白了就是方便我们管理自己的常用的一些代码,比如你开发中用到sass以及jade同时用到es ...

  7. hashMap_使用

    转]Java中HashMap遍历的两种方式原文地址: http://www.javaweb.cc/language/java/032291.shtml 第一种: Map map = new HashM ...

  8. java io基础(java.io)

    首先流分为输入和输出流,java分为字节流和字符流 1.字节输入流io.InputStream io.InputStream是一个抽象类它实现了Closeable接口的抽象类.那么它的子类(io包下) ...

  9. phpcms基础知识和配置

    一.设置界面 1.站点设置:相当于服务器上的站点 (1)站点修改:“关键词”和“描述”的修改,便于网络优化和搜索引擎对本网站的搜索. (2)模板的修改,可以自己加模板,引用自己模板 2.基本设置:所有 ...

  10. Docker网络代理设置

    背景 在一些实验室环境,服务器没有直接连接外网的权限,需要通过网络代理.我们通常会将网络代理直接配置在/etc/environment./etc/profile之类的配置文件中,这对于大部分操作都是可 ...