110,534
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="aaa" Grid.RowSpan="4" Visibility="Collapsed">
</Grid>
</Grid>
</Window>
UC控件
<UserControl x:Class="WPF.UC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Height="200" Width="300">
<Label>Loding......</Label>
</Grid>
</UserControl>
在第一个页面的后台代码
[code=csharp]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPF
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
Thread t;
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
t = new Thread(new ThreadStart(show));
t.Start();
}
void show()
{
this.aaa.Dispatcher.Invoke(new Action(() =>
{
this.aaa.Children.Add(new UC());
this.aaa.Visibility = Visibility.Visible;
}));
//相当于做其他的事情
Thread.Sleep(3000);
this.aaa.Dispatcher.Invoke(new Action(() =>
{
this.aaa.Visibility = Visibility.Collapsed;
}));
t.Abort();
}
}
}
[/code]