Win8应用开发 入门篇(二)富文本和消息框
MessageDialog默认是全屏的....
xaml代码:
<Page x:Class="App2_Dialog.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App2_Dialog" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Button x:Name="btn" Content="弹起" HorizontalAlignment="Left" Margin="212,466,0,0" VerticalAlignment="Top" Click="Button_Click_1" Width="100" Height="48" FontSize="22"/> <RichTextBlock x:Name="rtb" HorizontalAlignment="Left" Height="100" Margin="460,310,0,0" VerticalAlignment="Top" Width="313"/> </Grid> </Page>
c#代码:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; using Windows.UI.Popups; using Windows.UI.Xaml.Documents; // “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上有介绍 namespace App2_Dialog { /// <summary> /// 可用于自身或导航至 Frame 内部的空白页。 /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); addText(); } private void addText() { Paragraph ph = new Paragraph(); Run run = new Run(); run.Text = "记者:前几日,中国海监飞机多次巡航钓鱼岛附近海域,日本派出F-15战斗机进行无理拦截,请问中国军方是否有应对预案?中国军用飞机,特别是战斗机是否会对等到钓鱼岛空域进行巡逻。日常巡航中没有武器装备的中国海监飞机自身安全如何保证?一旦日方战斗机对我方飞机构成威胁,中国空军是否有应对预案?"; ph.Inlines.Add(run); InlineUIContainer ic = new InlineUIContainer(); HyperlinkButton hb = new HyperlinkButton(); hb.Content = "http://www.baidu.com/"; ic.Child = hb; ph.Inlines.Add(ic); rtb.Blocks.Add(ph); } /// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。Parameter /// 属性通常用于配置页。</param> protected override void OnNavigatedTo(NavigationEventArgs e) { } private void Button_Click_1(object sender, RoutedEventArgs e) { Windows.UI.Popups.MessageDialog msg = new MessageDialog("Hello MessageDialog!"); msg.Commands.Add(new UICommand("确定",null)); msg.Commands.Add(new UICommand("取消", null)); //msg.CancelCommandIndex = 1; //msg.DefaultCommandIndex = 1; msg.ShowAsync(); } } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步