Win10 UWP Popup


简单Popup

创建文件 -> XAML ->  空白页(BlankPage) -> 随便起名为 Page000.xaml

<Page
    x:Class="App1.Page000"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel>
            <Button Content="show Popup (using offset)" Click="ShowPopupOffsetClicked" />
        </StackPanel>
        <Popup VerticalOffset="10" HorizontalOffset="200" x:Name="StandardPopup">
            <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" BorderThickness="2" Width="200" Height="200">
                <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                    <TextBlock Text="Simple Popup" FontSize="24.667" HorizontalAlignment="Center"/>
                    <Button Content="Close" Click="ClosePopupClicked" HorizontalAlignment="Center"/>
                </StackPanel>
            </Border>
        </Popup>
    </Grid>
</Page>

Page000.xaml.cs:

namespace App1
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class Page000 : Page
    {
        public Page000()
        {
            this.InitializeComponent();
        }

        private void ShowPopupOffsetClicked(object sender, RoutedEventArgs e)
        {
            if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
        }

        private void ClosePopupClicked(object sender, RoutedEventArgs e)
        {
            if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
        }
    }
}








自定义Popup:

创建文件 -> XAML -> 用户控件(UserControl) -> 随便起名为 PopupUserControl.xaml

<UserControl
    x:Class="App1.PopupUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid Background="#f5f5f5">
        <StackPanel>
            <TextBlock Text="Type some input" FontSize="24.667"/>
            <TextBox Width="300" Height="55"/>
            <Button Content="Save" Click="Button_Click"/>
        </StackPanel>
    </Grid>
</UserControl>

PopupUserControl.xaml.cs:

namespace App1
{
    public sealed partial class PopupUserControl : UserControl
    {
        public PopupUserControl()
        {
            this.InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Popup p = this.Parent as Popup;
            if (p != null)
            {
                p.IsOpen = false;
            }
        }
    }
}

加载方式:

创建文件 -> XAML -> 空白页(BlankPage) -> 随便起名为 Page001.xaml

<Page
    x:Class="App1.Page001"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top">
        <StackPanel>
            <Button Content="Show Popup (using offset)" Click="ShowPopupOffsetClicked" />
        </StackPanel>
        <Popup x:Name="ParentedPopup" HorizontalOffset="200" VerticalOffset="200">
            <local:PopupUserControl />
        </Popup>
    </Grid>
</Page>

Page001.xaml.cs:

namespace App1
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class Page001 : Page
    {
        public Page001()
        {
            this.InitializeComponent();
        }

        private void ShowPopupOffsetClicked(object sender, RoutedEventArgs e)
        {
            if (!ParentedPopup.IsOpen)
            {
                ParentedPopup.IsOpen = true;
            }
        }
    }
}










资料来源:

点击打开链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值