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

  • 相关阅读:
    て和で用法的总结
    假如程序员上热搜是什么样的?网友:毫无违和感!
    一年精通,三年熟悉,五年了解,十年用过!C++真的这么难吗?
    新手上路,“hello word”其实是在告诉计算机又有菜鸟来了!
    从原理到方法,一步到位,教你如何应对C语言内存泄露!
    冰冷的英语字母,枯燥的编程教程,果断选择了放弃!真的吗?
    只有了解程序员的黑话,和他们打成一片获得buff加成,产品才能尽早上线!
    C语言编程小游戏「石头剪刀布」!源码分享~
    一行代码卖出570美元,什么样的代码能这么值钱?带你揭秘天价代码的内幕!
    源码解剖HashMap
  • 原文地址:https://www.cnblogs.com/qixue/p/3224321.html
Copyright © 2020-2023  润新知