[正则] WPF 求大神 怎么判断主窗体显示并加载完毕
我在做一个Loading 效果 一个窗体用来显示Loading 效果 一个窗体显示加载内容 (下面代码)
现在问题 当程序运行的时候 开始挺好 但是动画结束的早 显示内容的窗体没有显示加载内容 Loading 线程就关闭的 关闭后 过几秒才能显示加载内容
要解决的问题 怎么判断 窗体加载并显示完毕 我在关掉Loading线程? 通过控制线程 还是窗体?用消息循环 ? 怎么用? 求大神帮助 或给一个新的思路
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.Data;
using System.Threading;
using System.Windows.Threading;
namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public void winLoad()
{
readXML xml = new readXML();
DataTable table = xml.ReadMiniDTXml();
for (int i = 0; i < table.Rows.Count; i++)
{
Image user = new Image();
user.Name = "u" + (i + 1).ToString();
user.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + table.Rows[i]["path1"].ToString().Trim()));
user.Width = 100;
user.Height = 100;
this.stackPanel_Image.Children.Add(user);
}
}
Thread newWindowThread;
public delegate void AddButtonDelegate();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//加载进程
Thread thread = new Thread(DO);
// thread.IsBackground = true;
thread.Start();
//动画窗体进程
newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
newWindowThread.SetApartmentState(ApartmentState.STA);
//newWindowThread.IsBackground = true;
newWindowThread.Start();
}
/// <summary>
/// 开启新窗体 解决因加载,动画卡的问题
/// </summary>
private void ThreadStartingPoint()
{
Window2 tempWindow = new Window2();
tempWindow.Show();
System.Windows.Threading.Dispatcher.Run();
}
public void AddImage()
{
winLoad();
System.Windows.Application.Current.
}
void Window1_ContentRendered(object sender, EventArgs e)
{
newWindowThread.Abort(); //终止动画窗体进程
}
public void DO()
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new AddButtonDelegate(AddImage), DispatcherPriority.ContextIdle);
}
}
}
[解决办法]
Window 有个 Loaded 事件
[解决办法]
不是着个事件 不过找到了 解决了