• 设计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

  • 相关阅读:
    JDBC之一:JDBC快速入门
    AdapterView及其子类之四:基于ListView及SimpleAdapter实现列表
    AdapterView及其子类之三:基于ListView及ArrayAdapter实现列表
    AdapterView及其子类之二:使用ListActivity及ArrayAdapter创建列表
    AdapterView及其子类之一:基本原理(ListView、ListActivity类型)
    Fragment之一:基本原理
    Loader之二:CursorLoader基本实例
    Intent 跳转Activity
    Android 第三课 构建简单的用户界面
    android第二课:运行你的应用
  • 原文地址:https://www.cnblogs.com/qixue/p/3224321.html
Copyright © 2020-2023  润新知