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 ...
随机推荐
- Wireshark网络抓包(三)——网络协议
一.ARP协议 ARP(Address Resolution Protocol)地址解析协议,将IP地址解析成MAC地址. IP地址在OSI模型第三层,MAC地址在OSI第二层,彼此不直接通信: 在通 ...
- Kafka 0.10 KafkaConsumer流程简述
ConsumerConfig.scala 储存Consumer的配置 按照我的理解,0.10的Kafka没有专门的SimpleConsumer,仍然是沿用0.8版本的. 1.从poll开始 消费的规则 ...
- ECMAScript 6 笔记(六)
编程风格 1. 块级作用域 (1)let 取代 var (2)全局常量和线程安全 在let和const之间,建议优先使用const,尤其是在全局环境,不应该设置变量,只应设置常量. const优于le ...
- block之---数据传递
block值传递分为两种情况 1.值传递 含义: 类似于函数参数的值传递,block内部对值的改变对外部没有影响,外部改变对block内部也没有影响. 情况 block访问外部局部变量没有被任何关键字 ...
- 矢量切片(Vector tile)番外一:Proj4js
说明:番外篇是对正篇矢量切片(Vector tile)中提到的一些值得继续延伸的关注点继续进行探索和学习,所涉及的内容以解决实际问题为主要导向. 一.新的需求? 在完成了矢量切片的工作后,新的需求出现 ...
- java中浅层克隆和深层克隆
1.浅复制与深复制概念 浅复制(浅克隆) 被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.换言之,浅复制仅仅复制所考虑的对象,而不复制它所引用的对象 ...
- 【UWP】拖拽列表项的排序功能实现
在一些允许用户自定义栏目顺序的app(如:凤凰新闻.网易云音乐等),我们可以方便地拖拽列表项来完成列表的重新排序,进而完成对栏目顺序的重排.这个功能很人性化,而实现起来其实很简单(甚至都不用写什么后台 ...
- NodeJs之crypto
NodeJs版本:4.4.4 crypto nodejs提供了内置加密模块crypto. 加密模块提供了 HTTP 或 HTTPS 连接过程中封装安全凭证的方法. 它也提供了 OpenSSL 的哈希, ...
- java split函数应该注意的问题
split函数的参数是一个String,但是这个String会被解释成一个正则表达式. 比如 "test.txt".split(".").length得到的值是 ...
- 【转】svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
svn提交遇到恶心的问题,可能是因为上次cleanup中断后,进入死循环了. 错误如下 解决方法:清空svn的队列 1.下载sqlite3.exe 2.找到你项目的.svn文件,查看是否存在wc.db ...