windows phone 8.1开发:(消息弹出框)强大的ContentDialog
原文出自: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的更多相关文章
- 移动web:Tips消息弹出框
在web开发中经常会用到像alert这样的弹出消息,每个浏览器自带的消息弹出框都不相同.为了统一外观,实现自定义的功能,动手写一个弹出框插件. 对弹出框的实现要求如下: 1. 仿照IOS系统弹出外观 ...
- 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog
[源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...
- MessageBox页面消息弹出框类
MessageBox页面消息弹出框类: public class MessageBox { /// <summary> /// 自定义弹出窗口内容,不跳转 /// </summary ...
- WPF实战之一 桌面消息框(右下角消息弹出框)
此版本是根据别人的项目改造的,记录下笔记 原文:https://blog.csdn.net/catshitone/article/details/75089069 一.即时弹出 1.创建弹出框 新建一 ...
- Easyui-交互式消息弹出框
由于项目在优化的时候需要用到弹出框,按自己的想法是傻傻的用一些alert直接弹出得了,但是这样用户体验度不是特别好,影响界面美观,所以自己还是用了封装好的easyui给的消息框,怎么用呢,这个里面很有 ...
- Js:消息弹出框、获取时间区间、时间格式、easyui datebox 自定义校验、表单数据转化json、控制两个日期不能只填一个
(function ($) { $.messageBox = function (message) { $.messager.show({ title:'消息框提示', msg:message, sh ...
- Android 开发笔记 “弹出框”
AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this); builder.setMessage("Are y ...
- android开发学习 ------- 弹出框
这是一种方法,是我觉得简单易懂代码量较少的一种: /* 创建AlertDialog对象并显示 */ final AlertDialog alertDialog = new AlertDialog.Bu ...
- Windows Phone 几种弹出框提示方式
首先,我们需要在网络上下载一个Coding4Fun 然后,引用 using Coding4Fun.Phone.Controls.Toolkit; using Codin ...
随机推荐
- 《JAVASCRIPT高级程序设计》第四章
javascript变量是松散类型,它只是在特定时间表示特定值的一个名字而已:变量的值以及类型,可以在脚本的生命周期内改变.变量的类型,分为基本类型和引用类型两种,具体介绍如下图所示: 执行环境是Ja ...
- [html5] 学习笔记-表单新增的元素与属性(续)
本节主要讲解表单新增元素的controls属性.placeholder属性.List属性.Autocomplete属性.Pattern属性.SelectionDirection属性.Indetermi ...
- Express与NodeJs创建服务器的两种方法
NodeJs创建Web服务器 var http = require('http'); var server = http.createServer(function(req, res) { res.w ...
- Syslog4j如何实现接收日志
1.Syslog4j是一个实现Syslog(RFC3164)协议的Java开源类库包括客户端与服务器端.通过 UDP/IP, TCP/IP, TCP/IPover SSL/TLS, Unix Sysl ...
- DBCC CHECKIDENT在 SQL Server修改指定表的当前标识值
强制将当前标识值设为新值 ---最后 0 表示新值从1开始 --注意若前边有内容,最好删除,不然id会重复 DBCC CHECKIDENT ("表名称", RESEED, 0);
- css3 3d变换和动画——回顾
1.transform-style 属性指定嵌套原始是怎样在三维空间中呈现. 语法:transform-style: flat | preserve-3d flat 表示所有子元素在2D平面呈现. p ...
- OVS VxLAN Flow 分析 - 每天5分钟玩转 OpenStack(149)
OVS 的数据流向都是由 Flow 规则控制的,今天我们就来分析 VxLAN 的 Flow 规则.提个醒:这可能是本教程最烧脑的一节,let's rock it ! 下面分析控制节点上的 flow r ...
- 程序员的一生时间90%是用在编程上,而剩余的10%是活在世界上。刚进CSDN的博客看到这么句话
程序员的一生时间90%是用在编程上,而剩余的10%是活在世界上. 而自己呢?是个程序员呢还是个业余玩家!
- HTTP学习目录
前面的话 除了HTML.CSS.javascript这三门前端基础知识之外,HTTP恐怕是前端工程师最需要掌握的知识了,它是前端和后端沟通的桥梁,前端工程师需要能够调试HTTP.修复网络传输中可能遇到 ...
- Angular2 + Webpack项目搭建Demo
本文将从头开始编写实际的代码来完成一个angular2的demo. 题外话是其实angular2官网的快速开始项目已经很酷炫了,但其侧重快速二字,只够拿来练习玩耍,倒是github上确实已经有了一些不 ...