我是WPF中的新手,并尝试使用进度条设置启动画面我做了但是我有2个问题首先是当我的进度条结束主窗口打开重复:(。第二个问题是我无法关闭当前窗口。 thx for healping
using System.Threading;
using System.Windows.Controls;
using System.Windows.Threading;
namespace pro_karimian_
{
/// <summary>
/// Interaction logic for splash.xaml
/// </summary>
public partial class splash : Page
{
private double progcount = 0,endit = 1;
public splash()
{
new Thread(
delegate()
{
somefun();
if(progcount == endit)
{
//then close The window
}
}).Start();
InitializeComponent();
}
private void somefun()
{
for (int i = 0; i < 10; i++)
{
Thread.Sleep(100);
Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { progbar.SetValue(ProgressBar.ValueProperty, progcount); }, null);
progcount += 0.1;
}
endit = progcount;
Thread th = new Thread(
delegate()
{
MainWindow go = new MainWindow();
go.ShowDialog();
});
th.ApartmentState = ApartmentState.STA;
th.Start();
}
}
}
答案 0 :(得分:0)
代码存在问题我无法关闭表单caz我选择了一个页面而不是表单。我必须为此制作新的窗户 以下代码为false
public partial class splash : Page
{
.......
}
这是表格:
public partial class splash : Form
{
.......
}