windows phone 8.1開發:(訊息彈出框)強大的ContentDialog

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   使用   io   ar   

原文出自: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="5">                <Button  Content="查詞" Background="#FFC5246D"                        ></Button>            </GridViewItem>            <GridViewItem Margin="5">                <Button Content="翻譯"  Background="#FFEAC418"                        Name="translate" ></Button>            </GridViewItem>            <GridViewItem Margin="5">                <Button Content="生詞"  Background="#FFCB32DA"                       ></Button>            </GridViewItem>            <GridViewItem Margin="5">                <Button Content="關於"  Background="#FF58E4B5"                        ></Button>            </GridViewItem>        </GridView>    </Grid></ContentDialog>

調用方法和上面一樣,最終運行效果如下:

windows phone 8.1開發:(訊息彈出框)強大的ContentDialog

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.