设计Popup Window

设计一个Popup window, 在其中实现分享到Facebook 和Twitter 功能。

popup window 名称为 ShareView.xaml, 代码如下:

<phone:PhoneApplicationPage
    x:Class="MVA.ShareView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot" Background="#FF20422E">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="pageTitle" HorizontalAlignment="Center" Text="Share this Course" Margin="9,-1,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontSize="50" />
            
        </StackPanel>
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Border Grid.Row="0" Grid.Column="0" Tap="Border_Tap_1" >
                <Image Height="100" Width="100" Source="/Assets/Icon/facetitle.JPG" />
            </Border>
            <Border Grid.Row="0" Grid.Column="1" Tap="Border_Tap_2">
                <Image Height="100" Width="100" Source="/Assets/Icon/twittertitle.JPG"/>
            </Border>
            <Button Content="Close Share" Grid.Row="1" Grid.ColumnSpan="2" Height="72" HorizontalAlignment="Left" Margin="120,152,0,0" Name="btnShowPopUp" VerticalAlignment="Top" Width="235" Click="btnShowPopUp_Click_1" />
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

后台代码:

using System.Windows.Controls.Primitives;
using Microsoft.Phone.Tasks;

    public partial class ShareView : PhoneApplicationPage
    {
        public ShareView()
        {
            InitializeComponent();
        }

        private void btnShowPopUp_Click_1(object sender, RoutedEventArgs e)
        {
            ClosePopup();
        }

        private void ClosePopup()
        {
            Popup popupWindow = this.Parent as Popup;
            popupWindow.IsOpen = false;
        }

        private void Border_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var item = CommonConfig.SelectedItem;
            if (item != null)
            {
                string url=item.ID;
                CommonConfig.FaceBookSharePath = url;
                WebBrowserTask webTask = new WebBrowserTask();
                webTask.Uri = new Uri(CommonConfig.FaceBookSharePath, UriKind.Absolute);
                webTask.Show();
            }
        }

        private void Border_Tap_2(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var item = CommonConfig.SelectedItem;
            if (item != null)
            {
                string url = item.ID;
                CommonConfig.TwitterSharePath = url;
                WebBrowserTask webTask = new WebBrowserTask();
                webTask.Uri = new Uri(CommonConfig.TwitterSharePath, UriKind.Absolute);
                webTask.Show();
            }
        }
    }


触发 Popup Window 的事件:

        private void TextBlock_Tap_2(object sender, System.Windows.Input.GestureEventArgs e)
        {
            Popup popupView;
            popupView = new Popup();

            popupView.Child = new ShareView();
            popupView.IsOpen = true;
            popupView.VerticalOffset = 100;
            popupView.HorizontalOffset = 40;
        }

参考:

http://www.mindfiresolutions.com/Display-Popup-Box-in-Windows-2108.php

原文地址:https://www.cnblogs.com/qixue/p/3224321.html