【发布时间】:2014-05-27 15:41:11
【问题描述】:
在主窗口出现后,我有一些东西需要写入屏幕。但实际情况是 Loaded 事件代码已完全执行,然后窗口才打开。我需要做什么来改变它?
*我不关心使用任何其他事件,除了“加载”。
public partial class MainWindow : Window
{
public const string UpdatedClientComputerURL = @"net.tcp://localhost:8181/";
public const string UpdatedClientComputerHostName = "Client1";
public MainWindow()
{
InitializeComponent();
ClientAdministration.ConnectedToServerEvent += ClientAdministration_ConnectedToServerEvent;
ClientAdministration.RestoredDownloadsEvent += ClientAdministration_RestoredDownloadsEvent;
StatusLabel.Text = "Connecting to server...";
}
void ClientAdministration_RestoredDownloadsEvent()
{
StatusLabel.Text = "Opening TorrentS...";
}
void ClientAdministration_ConnectedToServerEvent(bool Conncted)
{
if(Conncted)
StatusLabel.Text = "Connected to server...";
else
StatusLabel.Text = "Failed connect to server...";
Task.Delay(5000).Wait();
StatusLabel.Text ="Restoring downloads...";
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
///***I want the window to be open befor this code get excuted!!!!!***
ClientAdministration.ConnectToServer(UpdatedClientComputerURL, UpdatedClientComputerHostName);
ClientAdministration.RestoreDownloads();
}
}
【问题讨论】:
-
试试
ContentRendered事件。 -
tnx.工作完美。但是它们之间有什么区别呢?
-
关于区别,看我的
answer。
标签: wpf