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

时间:2014-06-01 21:00:46

标签: c# .net wpf xaml windows-phone-8

嗨我需要如何在xaml for windows phone中制作叠加页面?就像,如果我点击一个按钮,它将显示叠加信息加载...然后实际开始工作。我已经能够在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>

你能告诉我如何制作叠加信息吗?

1 个答案:

答案 0 :(得分:2)

如果你需要并覆盖它,那就是。 首先,您需要一个用户控件。

<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();

找到有效的Here on Nokia Developers community