为什么出现app icon templatee windows app

为你推送和解读最前沿、最有料的科技创投资讯
36Kr股权投资
汇集行业内最优质创业项目的股权投资平台
聚集15家顶级投资机构的专业互联网融资平台
聚集全球最优秀的创业者,项目融资率接近97%,领跑行业温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(13676)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_083065',
blogTitle:'windows 7中Word 2010默认模板位置',
blogAbstract:'&&&&& 带宏命令的Word模板是我们常用的,windows7中Word2010的默认模板位置有所变化。具体如下:\r\nC:\\用户\\Username(本机用户名)\\AppData\\Roaming\\Microsoft\\Templates\r\n或者\r\nC:\\Users\\Username(本机用户名)\\AppData\\Roaming\\Microsoft\\Templates\r\n模板名称为Normal.dotm。\r\n&\r\n使用自己原来的宏命令模板替换默认模板并运行后,可能会出现在Word 2010的“加载项”栏目中,亦可手动添加按钮。',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:5,
publishTime:6,
permalink:'blog/static/',
commentCount:2,
mainCommentCount:2,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Windows App开发之使用通知与动态磁贴
使用Toast通知示例前面我们使用了MessageDialog来作为弹窗,这里来介绍一个更加高大上的Toast通知。Toast通知本质上动力是由XML来提供的,一开始我还不相信不知道XML原来有这么大的威力。现在就来看看和Toast相关的知识。1)实例化ToastNotification类。ToastNotification toast1 = new ToastNotification(xdoc);
2)使用ToastNotificationManager来管理Toast通知,包括添加、展示、移除、获取通知等等。ToastNotificationManager.CreateToastNotifier().Show(toast1);3)在第一步中的xdoc就是一段XML数据,它从何而来呢?XmlDocument xdoc = new XmlDocument();4)上一步代码实例化了一个XML,但是它没有数据呀,数据从哪来呢?xdoc.LoadXml(txtXML.Text);5)这段代码就将一段Text导入了XML中。而Text数据有很多种获取方式。在下文中自然会提到。Toast的XML模板有许多,我们可以直接来获取它们。用枚举和强大的var即可。var items = Enum.GetNames(typeof(ToastTemplateType));那么就正式开工了,因为重复的属性太多了我就大概设置了2个Style资源。
&Page.Resources&
&Style TargetType="TextBlock" x:Key="StyleHeaderTextBlock"&
&Setter Property="FontSize" Value="40"/&
&Setter Property="FontFamily"
Value="华文琥珀"/&
&Setter Property="Foreground" Value="HotPink"/&
&Setter Property="Margin" Value="12"/&
&Style TargetType="Button" x:Key="StyleToastButton"&
&Setter Property="Width" Value="180"/&
&Setter Property="Height" Value="50"/&
&Setter Property="Background" Value="Aqua"/&
&Setter Property="FontSize" Value="21"/&
&Setter Property="Margin" Value="12"/&
&Setter Property="Content" Value="显示Toast通知" /&
&/Page.Resources&下面是第一部分用于生成Toast通知。
&StackPanel Orientation="Vertical" Grid.Column="0" Margin="12"&
&TextBlock Text="生成Toast通知" Style="{StaticResource StyleHeaderTextBlock}"/&
&StackPanel Orientation="Horizontal" HorizontalAlignment="Left"&
&TextBlock FontSize="24" Foreground="Wheat" Text="请选择一个模板:" VerticalAlignment="Center"/&
&ComboBox Name="comboBoxToast" Foreground="Green"
Width="275"
SelectionChanged="comboBoxToast_SelectionChanged"/&
&/StackPanel&
&TextBox Foreground="Green" x:Name="txtXML" HorizontalAlignment="Left" Width="500" Height="400" Header="模板XML:" TextWrapping="Wrap" FontSize="24"/&
&Button Name="btnShowToast1" Click="btnShowToast1_Click"
Style="{StaticResource StyleToastButton}"/&
&/StackPanel&后台代码也蛮容易的,利用上面讲的就好了。
public MainPage()
this.InitializeComponent();
var items = Enum.GetNames(typeof(ToastTemplateType));
this.comboBoxToast.ItemsSource =
private void comboBoxToast_SelectionChanged(object sender, SelectionChangedEventArgs e)
string tempt = ((ComboBox)sender).SelectedItem as string;
if (!string.IsNullOrEmpty(tempt))
ToastTemplateType template = (ToastTemplateType)Enum.Parse(typeof(ToastTemplateType), tempt);
XmlDocument xdoc = ToastNotificationManager.GetTemplateContent(template);
txtXML.Text = xdoc.GetXml();
private void btnShowToast1_Click(object sender, RoutedEventArgs e)
if (txtXML.Text == "")
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(txtXML.Text);
ToastNotification toast1 = new ToastNotification(xdoc);
ToastNotificationManager.CreateToastNotifier().Show(toast1);
}模板是这样用的……在src中填入图片的路径也可以在Toast中显示图像哦,赶紧试试吧……接下来是第二段啦,和前面的很是类似……%20%20%20%20&StackPanel%20Orientation="Vertical"%20Grid.Column="1"&%20%20%20%20%20%20%20%20%20%20%20%20&TextBlock%20Text="更改Toast通知的提示音"%20Style="{StaticResource%20StyleHeaderTextBlock}"/&%20%20%20%20%20%20%20%20%20%20%20%20&TextBlock%20Margin="12"%20Text="请输入Toast消息内容:"%20FontSize="24"/&%20%20%20%20%20%20%20%20%20%20%20%20&TextBox%20Margin="12"%20Height="50"%20x:Name="txtMesaage"/&%20%20%20%20%20%20%20%20%20%20%20%20&TextBlock%20%20Margin="12"%20FontSize="24"%20Text="请选择一种提示声音:"/&%20%20%20%20%20%20%20%20%20%20%20%20&ComboBox%20Margin="12"%20Height="50"%20x:Name="comboBoxAudio"%20Width="400"%20HorizontalAlignment="Left"&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&ComboBoxItem%20IsSelected="True"&ms-winsoundevent:Notification.Default&/ComboBoxItem&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&ComboBoxItem&ms-winsoundevent:Notification.IM&/ComboBoxItem&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&ComboBoxItem&ms-winsoundevent:Notification.Mail&/ComboBoxItem&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&ComboBoxItem&ms-winsoundevent:Notification.Reminder&/ComboBoxItem&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&ComboBoxItem&ms-winsoundevent:Notification.Looping.Alarm&/ComboBoxItem&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&ComboBoxItem&ms-winsoundevent:Notification.Looping.Call&/ComboBoxItem&%20%20%20%20%20%20%20%20%20%20%20%20&/ComboBox&%20%20%20%20%20%20%20%20%20%20%20%20&StackPanel%20Orientation="Horizontal"&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&CheckBox%20x:Name="checkBoxLoop"%20Margin="12"%20Content="循环播放"/&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&CheckBox%20x:Name="checkBoxSilent"%20Margin="12"%20Content="静音"/&%20%20%20%20%20%20%20%20%20%20%20%20&/StackPanel&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&Button%20Name="btnShowToast2"%20Click="btnShowToast2_Click"%20%20Style="{StaticResource%20StyleToastButton}"/&%20%20%20%20%20%20%20%20&/StackPanel&上面代码中的“ms-winsoundevent:Notification.Default”都是填到src中的用于设置声音,还可以在loop、silent中设置是否循环以及是否静音,那到底该怎么用呢?应该将这些属性全部都填入到XML中。xmlContent%20=%20string.Format(%20%20%20%20%20"&toast%20duration='{0}'&"%20+%20%20%20%20%20%20%20%20%20%20%20"&visual&"%20+%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"&binding%20template='ToastText01'&"%20+%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"&text%20id='1'&{1}&/text&"%20+%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20"&/binding&"%20+%20%20%20%20%20%20%20%20%20%20%20"&/visual&"%20+%20%20%20%20%20%20%20%20%20%20%20"&audio%20src='{2}'%20loop='{3}'%20silent='{4}'/&"%20+%20%20%20%20%20"&/toast&",%20%20%20%20%20toastDuration,%20msg,%20audioSrc,%20isLoop,%20isSilent%20%20%20%20);%20%20%20%20%20%20%20%20%20%20%20%20%20上面用的xmlContent也要先定义出来,一开始设置为Empty就好。string%20xmlContent%20=%20string.Empty;%20%20isLoop和isSilent属性都可以借助于三目运算符在CheckBox中获取来。string%20isLoop%20=%20checkBoxLoop.IsChecked%20==%20true%20?%20"true"%20:%20"false";%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20string%20audioSrc%20=%20(comboBoxAudio.SelectedItem%20as%20ComboBoxItem).Content.ToString();%20%20%20%20%20%20%20%20%20%20string%20toastDuration%20=%20checkBoxLoop.IsChecked%20==%20true%20?%20"long"%20:%20"short";%20%20%20%20%20%20%20%20%20%20%20%20string%20isSilent%20=%20checkBoxSilent.IsChecked%20==%20true%20?%20"true"%20:%20"false";%20%20%20%20%20%20%20%20当然,考虑得更加周到些,用户可以在还没有输入通知内容就点了显示Toast通知按钮,对此用三目运算符也是极好的选择。string%20msg%20=%20txtMesaage.Text%20==%20""%20?%20"你还没有输入Toast通知的内容呢……"%20:%20txtMesaage.Text;%20%20%20这些准备工作都写好了以后呢就该设置Toast通知了,和上面的Toast1类似哦,大家试试。可是这些通知都没有时间性可言,因为有时候我们需要定在一个时间来执行Toast通知。这自然也是可以实现的。先作如下界面设计。%20%20%20%20%20%20&StackPanel%20Orientation="Vertical"%20Grid.Column="2"&%20%20%20%20%20%20%20%20%20%20%20%20&TextBlock%20Text="计划时间显示Toast通知"%20Style="{StaticResource%20StyleHeaderTextBlock}"/&%20%20%20%20%20%20%20%20%20%20%20%20%20%20&StackPanel%20Orientation="Horizontal"%20Height="60"&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&TextBlock%20FontSize="28"%20Text="计划在"%20%20VerticalAlignment="Center"/&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&TextBox%20Name="tBoxTime"%20FontSize="28"%20Width="60"%20Height="45"%20VerticalAlignment="Center"/&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&TextBlock%20FontSize="28"%20Text="秒后显示Toast通知"%20VerticalAlignment="Center"/&%20%20%20%20%20%20%20%20%20%20%20%20&/StackPanel&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&Button%20Name="btnShowToast3"%20Click="btnShowToast3_Click"%20%20Style="{StaticResource%20StyleToastButton}"/&%20%20%20%20%20%20%20%20&/StackPanel&后台代码如下。%20%20%20%20%20%20%20%20private%20async%20void%20btnShowToast3_Click(object%20sender,%20RoutedEventArgs%20e)%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20int%20toastTime;%20%20%20%20%20%20%20%20%20%20%20%20try%20%20%20%20%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20toastTime%20=%20int.Parse(tBoxTime.Text.ToString());%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20XmlDocument%20xdoc%20=%20ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20txtnodes%20=%20xdoc.GetElementsByTagName("text");%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20txtnodes[0].InnerText%20=%20"你好,这是一条定时为"+toastTime.ToString()+%20"秒的Toast消息。";%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ScheduledToastNotification%20toast3%20=%20new%20ScheduledToastNotification(xdoc,%20DateTimeOffset.Now.AddSeconds(toastTime));%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast3);%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20catch%20(Exception%20ex)%20%20%20%20%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Windows.UI.Popups.MessageDialog%20messageDialog%20=%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20Windows.UI.Popups.MessageDialog(ex.Message);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20messageDialog.ShowAsync();%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20在这个小程序中因为侧重于讲解定时而非Toast的通知样式,因此就选用了比较简单的ToastText01模板。而后找出Text节点,并向该节点写入内容。最后就是创建Toast通知了。ScheduledToastNotification%20toast3%20=%20new%20ScheduledToastNotification(xdoc,%20DateTimeOffset.Now.AddSeconds(toastTime));同样为了防止用户没有在TextBox中输入时间或输入了错误格式的时间比如“5秒”而做了try、catch异常检测。当然了,在实际产品中,这里可就要做得更加完美了,时间用TextBox来输入并不是一件好事,而应用我们前面介绍的TimePicker。给这3段程序来张全家福吧~使用动态磁贴示例动态磁贴是什么,相信大家用了这么久的Windows%208/8.1/10早就非常了解了吧。像什么小磁贴、中磁贴、宽磁贴、大磁贴,还有这里的应用商店Logo等,大家在下面根据不同的分辨率选择合适的图片就好啦。下面来做一个更新磁贴页面的功能,这是页面XML部分。&StackPanel%20Margin="12"&%20%20%20%20%20%20&StackPanel%20Orientation="Horizontal"&%20%20%20%20%20%20%20%20%20%20&TextBlock%20FontSize="28"%20Text="选择模板:"%20VerticalAlignment="Center"/&%20%20%20%20%20%20%20%20%20%20&ComboBox%20x:Name="comboBoxTile"%20%20Width="400"%20SelectionChanged="comboBoxTile_SelectionChanged"/&%20%20%20%20%20%20&/StackPanel&%20%20%20%20%20%20&TextBox%20x:Name="textBoxXML"%20TextWrapping="Wrap"%20FontSize="22"%20Header="XML文档"%20Width="420"%20Height="320"%20HorizontalAlignment="Left"%20Margin="12"/&%20%20%20%20%20%20&Button%20Name="btnTile"%20%20Content="更新磁贴"%20Click="btnTile_Click"%20Style="{StaticResource%20StyleToastButton}"/&&/StackPanel&在后台代码的Main函数中,获取TileTemplateType枚举并绑定到ComboBox上。var%20itemsTile%20=%20Enum.GetNames(typeof(TileTemplateType));this.comboBoxTile.ItemsSource%20=%20itemsT下面的代码和前面的Toast真的非常类似,所以我才把这两节连在一起来写了。Button按钮的Click事件中,和之前一样建一个XML,然后加载到TileNotification类的实例中。最后就是TileUpdateManager类,也就是磁贴更新。private%20void%20btnTile_Click(object%20sender,%20RoutedEventArgs%20e){%20%20%20%20if%20(this.textBoxXML.Text%20==%20"")%20%20%20%20%20%20%20%20%20%20return;%20%20%20%20XmlDocument%20xdoc%20=%20new%20XmlDocument();%20%20%20%20xdoc.LoadXml(this.textBoxXML.Text);%20%20%20%20TileNotification%20tileNotifi%20=%20new%20TileNotification(xdoc);%20%20%20%20TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotifi);}private%20void%20comboBoxTile_SelectionChanged(object%20sender,%20SelectionChangedEventArgs%20e){%20%20%20%20TileTemplateType%20tileTemplate%20=%20(TileTemplateType)Enum.Parse(typeof(TileTemplateType),%20%20%20%20%20%20%20%20this.comboBoxTile.SelectedItem%20as%20string);%20%20%20%20XmlDocument%20xdoc%20=%20TileUpdateManager.GetTemplateContent(tileTemplate);%20%20%20%20this.textBoxXML.Text%20=%20xdoc.GetXml();}当然了,如果你的APP不满足于一个磁贴,你也可以创建第二个磁贴哟!依旧和Toast通知的XML类似,它也有好多属性的……Arguments:使用该字符串参数在通过次要磁贴启动应用程序时会传递给Application类的OnLaunched方法,这样一来应用程序就可以根据传入的参数来执行特定的操作。BackgroundColor:设置磁贴的背景色。DisplayName和ShortName:设置显示在磁贴上的文本。Logo等:设置磁贴的图标,用Uri。ForegroundText:磁贴上文本的颜色,可用的选项有深色、浅色等。TileID:设置磁贴的唯一标识ID,创建新磁贴前用SecondaryTile.Exists判断是否已经存在。在添加第二磁贴的Button的Click事件中:private%20async%20void%20btnCreateTile(object%20sender,%20RoutedEventArgs%20e){%20%20%20%20if(SecondaryTile.Exists(textTileID.Text))%20%20%20%20{%20%20%20%20%20%20%20%20textBlockMsg.Text="该ID磁贴已经存在";%20%20%20%20%20%20%20%20return%20;%20%20%20%20}%20%20%20%20Uri%20uriImg=new%20Uri("ms-appx:///Assests/uriImg.png");
// 创建第二磁贴
SecondaryTile secTile=new SecondaryTile();
this.Tag=secT
secTile.DisplayName=textBlockDisplayName.T
secTile.TileID=textBlockID.T
secTile.Arguments="second"; // 在后面有用到
// 设置图标
secTile.VisualElements.BackgroundColor=Windows.UI.Colors.G
bool r=await secTile.RequestCreateAsync();
textBlockMsg.Text=r == true ?"磁贴创建成功啦.":"磁贴创建失败了哎.";
// 返回测试结果如果希望点击第二磁贴导航到特定的页面,就需要重写该页面的OnNavigatedTo方法。preteced async override void OnNavigatedTo(NavigationEventArgs e){
if(e.Parameter is Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
var arg=e.Parameter as Windows.ApplicationModel.Activation.LaunchActivateEventA
}}if(rootFrame.Content==null){
if(e.Arguments=="second")
rootFrame.Navigate(typeof(OtherPage),e);
rootFrame.Navigate(typeof(MainPage));}这里的参数”second”就是上面设置那个Arguments哦,它的作用就在于这里呢。
版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。分享智慧之光,保卫知识产权。
最新教程周点击榜
微信扫一扫Are you Sure?
Disclaimer:&The template provided in the form of Visual Studio project (C# and JS) is meant to act as a starter kit for Windows 8 Store apps development. You are&recommended to change or modify the look and feel to
suit the branding that is required for your app. The template by no means restricts you to stick to the layout, navigation or other aspects indicated.
Project Description
Education Big Picture template will help if you want to build an app which has the following sections
Courses Section
What&s Happening section
Courses detail section
The Education template is an emulation of an Education app with placeholders for Courses, Latest updates in the University.
You can leverage this template even if you are not building an Education app, but the implementation scenario is closest to the template. Please refer to the &snapshots& folder under the
root template folder to get a glimpse of the template look and feel.
Download includes the following
Source (C# and JS) Package Snapshots Documentation
Last edited
by , version 2
EducationBigPicture5346人阅读
事过境迁(191)
Windows Store应用程序有点像Web页面,一般而言,我们只有一个窗口,不会像传统的桌面应用程序那样,使用多个子窗体。
前面我们也讨论过MessageDialog类用来弹出对话框,但是,它只能显示文本信息,如果一些复杂的内容,就不能满足我们的要求了。本来考虑Windows.UI.Core命名空间下的CoreWindowDialog类,但,后来发现这个类貌似一个空壳子,反正我是不知道这个类是怎么用的,那么,咋办呢,有没有其它方法呢?
其实所谓的弹出层,说白了,其本质就是一个控件,这个控件我们如果玩过WPF,会觉得灰常熟悉,谁呢?就是这位帅哥——Popup(位于Windows.UI.Xaml.Controls.Primitives下),怎么样,似曾相识吧?
我们总结,每个弹出层,无论其内容是什么,都有以下共同特点:
1、有一个半透明的层覆盖在现有UI上,以阻止用户操作弹出对话框下的UI元素。
2、除了内容不同,弹出层的大小位置以及背景都是一个样的。
这样的话,我们不妨自己来写一个控件,这个控件具有内容模型,这样,在弹出框中需要什么内容,我们只需设置其Content就行了。
下面,我们就实地演练一下吧。
1、用动VS,新建一个空白页面项目。
2、在“解决方案资源管理器”上右击,从菜单中选择“添加”-“新建项”。
在接下来的窗口中选择“模板化控件”,输入控件名字,确定。
让后你会看到下面这个。
3、打开Generic.xaml,先为控件定义好模板。
&ResourceDictionary
xmlns=&/winfx/2006/xaml/presentation&
xmlns:x=&/winfx/2006/xaml&
xmlns:local=&using:App1&&
&Style TargetType=&local:PopControl&&
&Setter Property=&Template&&
&Setter.Value&
&ControlTemplate TargetType=&local:PopControl&&
&Rectangle Canvas.ZIndex=&0& Fill=&Black& Opacity=&0.4&/&
&ContentPresenter Content=&{TemplateBinding Content}& HorizontalAlignment=&{TemplateBinding HorizontalContentAlignment}& VerticalAlignment=&{TemplateBinding VerticalContentAlignment}& ContentTemplate=&{TemplateBinding ContentTemplate}& /&
&/ControlTemplate&
&/Setter.Value&
&/ResourceDictionary&
模板一点也不复杂,接下来是核心部分,就是控件的逻辑代码。
using System.Collections.G
using System.L
using Windows.UI.X
using Windows.UI.Xaml.C
using Windows.UI.Xaml.D
using Windows.UI.Xaml.D
using Windows.UI.Xaml.I
using Windows.UI.Xaml.M
using Windows.UI.Xaml.Controls.P
using Windows.UI.Xaml.Media.A
namespace App1
public class PopControl : ContentControl
Popup m_pop =
public PopControl()
this.DefaultStyleKey = typeof(PopControl);
// 弹出层的宽度等于窗口的宽度
this.Width = Window.Current.Bounds.W
// 弹出层的高度等于窗口的高度
this.Height = Window.Current.Bounds.H
this.HorizontalContentAlignment = Windows.UI.Xaml.HorizontalAlignment.S
this.m_pop = new Popup();
// 将当前控件作为Popup的Child
this.m_pop.Child =
/// &summary&
/// 获取Popup的ChildTransitions集合
/// &/summary&
public TransitionCollection PopTransitions
if (m_pop.ChildTransitions == null)
m_pop.ChildTransitions = new TransitionCollection();
return m_pop.ChildT
/// &summary&
/// 显示弹出层
/// &/summary&
public virtual void ShowPop()
if (this.m_pop != null)
this.m_pop.IsOpen =
/// &summary&
/// 隐藏弹出层
/// &/summary&
public virtual void HidePop()
if (this.m_pop != null)
this.m_pop.IsOpen =
大至原理是这样的,把控件的大小设置和当前窗口的大小相等,这样确保弹出层可以完全覆盖在UI上。接着把当前控件作为Popup控件的Child元素,而控件的显示与隐藏,其实就是设置Popup的IsOpen属性。
为了方便派生类扩展,ShowPop和HidePop方法都用了virtual关键字。
4、接下来,新增一个用户控件,它作为弹出层的内容。
&UserControl
x:Class=&App1.ucReg&
xmlns=&/winfx/2006/xaml/presentation&
xmlns:x=&/winfx/2006/xaml&
xmlns:local=&using:App1&
xmlns:d=&/expression/blend/2008&
xmlns:mc=&http://schemas.openxmlformats.org/markup-compatibility/2006&
mc:Ignorable=&d&
d:DesignHeight=&700&
d:DesignWidth=&900&&
&UserControl.Resources&
&Style x:Key=&t& TargetType=&TextBlock&&
&Setter Property=&FontSize& Value=&20&/&
&Setter Property=&VerticalAlignment& Value=&Center&/&
&Setter Property=&Margin& Value=&6,0,21,0&/&
&Style x:Key=&w& TargetType=&FrameworkElement&&
&Setter Property=&Margin& Value=&5,7,0,5&/&
&/UserControl.Resources&
&Grid VerticalAlignment=&Center& Background=&Green&&
&Grid Margin=&0,50,0,32& Width=&560&&
&StackPanel&
&TextBlock Text=&用户注册& Margin=&0,0,0,34& Style=&{StaticResource PageHeaderTextStyle}&/&
&Grid.ColumnDefinitions&
&ColumnDefinition Width=&Auto&/&
&ColumnDefinition/&
&/Grid.ColumnDefinitions&
&Grid.RowDefinitions&
&RowDefinition Height=&Auto&/&
&RowDefinition Height=&Auto&/&
&RowDefinition Height=&Auto&/&
&RowDefinition Height=&Auto&/&
&RowDefinition Height=&Auto&/&
&/Grid.RowDefinitions&
&TextBlock Style=&{StaticResource t}& Grid.Row=&0& Grid.Column=&0& Text=&姓名:&/&
&TextBox Grid.Row=&0& Grid.Column=&1& Style=&{StaticResource w}&/&
&TextBlock Grid.Row=&1& Grid.Column=&0& Text=&性别:& Style=&{StaticResource t}&/&
&ComboBox Grid.Row=&1& Grid.Column=&1& Style=&{StaticResource w}&&
&ComboBoxItem Content=&男& IsSelected=&True&/&
&ComboBoxItem Content=&女& /&
&/ComboBox&
&TextBlock Style=&{StaticResource t}& Text=&电邮:& Grid.Row=&2& Grid.Column=&0&/&
&TextBox Style=&{StaticResource w}& Grid.Row=&2& Grid.Column=&1&/&
&TextBlock Style=&{StaticResource t}& Text=&手机:& Grid.Row=&3& Grid.Column=&0&/&
&TextBox Grid.Column=&1& Grid.Row=&3& Style=&{StaticResource w}&/&
&TextBlock Text=&地址:& Style=&{StaticResource t}& Grid.Row=&4& Grid.Column=&0&/&
&TextBox Style=&{StaticResource w}& Grid.Row=&4& Grid.Column=&1&/&
&StackPanel Orientation=&Horizontal& Margin=&0,15,0,7& HorizontalAlignment=&Center&&
&Button Content=&确定& Padding=&45,5& Click=&onClick&/&
&Button Content=&取消& Padding=&45,5& Margin=&22,0,0,0& Click=&onClick&/&
&/StackPanel&
&/StackPanel&
&/UserControl&
using System.Collections.G
using System.IO;
using System.L
using Windows.F
using Windows.Foundation.C
using Windows.UI.X
using Windows.UI.Xaml.C
using Windows.UI.Xaml.Controls.P
using Windows.UI.Xaml.D
using Windows.UI.Xaml.I
using Windows.UI.Xaml.M
using Windows.UI.Xaml.N
namespace App1
public sealed partial class ucReg : UserControl
PopControl _
public ucReg(PopControl c)
this.InitializeComponent();
private void onClick(object sender, RoutedEventArgs e)
if (_pc != null)
_pc.HidePop();
为了方便控制PopControl,在用户控件中声明一个PopControl,在用户控件类的构造函数中传递。
5、最后,我们在MainPage.xaml中测试这个弹出框。
x:Class=&App1.MainPage&
xmlns=&/winfx/2006/xaml/presentation&
xmlns:x=&/winfx/2006/xaml&
xmlns:local=&using:App1&
xmlns:d=&/expression/blend/2008&
xmlns:mc=&http://schemas.openxmlformats.org/markup-compatibility/2006&
mc:Ignorable=&d&&
&Grid Background=&{StaticResource ApplicationPageBackgroundThemeBrush}&&
&Button Content=&弹出对话框& Click=&onPop&/&
using System.Collections.G
using System.IO;
using System.L
using Windows.F
using Windows.Foundation.C
using Windows.UI.X
using Windows.UI.Xaml.C
using Windows.UI.Xaml.Controls.P
using Windows.UI.Xaml.D
using Windows.UI.Xaml.I
using Windows.UI.Xaml.M
using Windows.UI.Xaml.N
namespace App1
public sealed partial class MainPage : Page
public MainPage()
this.InitializeComponent();
private void onPop(object sender, RoutedEventArgs e)
PopControl pc = new PopControl();
ucReg uc = new ucReg(pc);
pc.Content =
pc.ShowPop();
好了,现在可以运行,效果就像下图所示,还不错吧。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1387451次
积分:17227
积分:17227
排名:第356名
原创:215篇
评论:1357条
文章:25篇
阅读:282169
文章:15篇
阅读:84976
文章:40篇
阅读:169294
阅读:16739
文章:52篇
阅读:358909
(6)(3)(5)(3)(2)(5)(8)(6)(6)(14)(12)(17)(9)(11)(7)(6)(9)(7)(10)(16)(11)(10)(12)(16)(2)(3)

我要回帖

更多关于 appicontemplate 的文章

 

随机推荐