繁体   English   中英

如何在wp8 xaml C#中创建按钮事件后创建加载页面

[英]how to create a loading page after a button event in wp8 xaml C#

嗨,我需要如何在Windows Phone的xaml中制作类似页面的叠加层? 就像,如果我点击一个按钮,它将显示一个类似于消息加载的叠加图……然后真正开始工作。 我所有能够在xaml中创建一个弹出窗口。

<Popup x:Name="myPopup" HorizontalAlignment="Center" VerticalAlignment="Center" >
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBlock FontSize="25" Grid.Column="1" Margin="20" Text="loading"/>
    </Grid>
</Popup>

你能告诉我如何使像消息一样的覆盖吗?

如果您需要并覆盖在那里。 首先,您需要一个用户控件。

<UserControl x:Class="ABC.Test.OverLay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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}"
d:DesignHeight="800" d:DesignWidth="480">

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="400"/>
        <RowDefinition Height="400"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="1">
        <ProgressBar IsIndeterminate="True" Foreground="Red" Height="80" Width="480" VerticalAlignment="Center"/>
        <TextBlock Text="loading" Foreground="Red" HorizontalAlignment="Center" FontSize="20"/>
    </StackPanel>
</Grid>

在Codebehind中:

public OverLay()
    {
        InitializeComponent();
        this.LayoutRoot.Height = Application.Current.Host.Content.ActualHeight;
        this.LayoutRoot.Width = Application.Current.Host.Content.ActualWidth;
        SystemTray.IsVisible = false;
    }

在显示叠加层的页面中,创建一个弹出窗口实例,如下所示:

private Popup popup;

InitializeComponent()之后初始化它,如下所示:

this.popup = new Popup();

如果您需要显示叠加层,请尝试以下操作:

        this.LayoutRoot.Opacity = 0.2;
        OverLay _ovr = new OverLay();            
        this.popup.Child = _ovr;
        this.popup.IsOpen = true;
        BackgroundWorker _worker = new BackgroundWorker();
        _worker.DoWork += (s, a) =>
        {
            //you can do your work here.
            Thread.Sleep(3000);
        };
        _worker.RunWorkerCompleted += (s, a) =>
        {
            popup.IsOpen = false;
            this.LayoutRoot.Opacity = 1.0;
        };

        _worker.RunWorkerAsync();

在诺基亚开发者社区中找到此处的工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM