【问题标题】:how to create a loading page after a button event in wp8 xaml C#如何在wp8 xaml C#中的按钮事件后创建加载页面
【发布时间】:2014-06-01 21:00:45
【问题描述】:

您好,我需要如何在 xaml 中为 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>

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

【问题讨论】:

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


    【解决方案1】:

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

    <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>
    

    在代码隐藏中:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多