如何在wp8xaml c#中创建按钮事件后的加载页面
本文关键字:事件 加载 按钮 创建 wp8xaml | 更新日期: 2023-09-27 18:06:05
嗨,我需要如何在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>
你能告诉我如何使叠加像消息吗?
如果你需要和覆盖,它在那里。首先你需要一个usercontrol。
<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>
In 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();
在诺基亚开发者社区找到工作