PDA

View Full Version : سوال: اجرای دستورات بعد از ناپدید شدن Grid



water_lily_2012
دوشنبه 24 مرداد 1390, 17:53 عصر
سلام
من دو تا گرید در برنامه دارم که با کلیک روی یک دکمه گریدی که دکمه داخلش هست باید ناپدید بشه و گرید دوم ظاهر بشه. و بعد تعدادی دستور اجرا بشه.
متاسفانه اول دستورات اجرا میشه و بعد گرید ناپدید میشه و گرید بعدی ظاهر میشه در صورتیکه دستورات در رویداد کلیک دکمه بعد از دستورات ناپدید شدن هست.


private void btnLogin_Click(object sender, RoutedEventArgs e)
{
MainGrid.Visibility = Visibility.Hidden;
TestConnectGrid.Visibility = Visibility.Visible;


Login login = new Login();
int GetUser = login.VerifyUserName("Reza", "521");
if (GetUser == 0)
MessageBox.Show("no");
}

رضا عربلو
سه شنبه 25 مرداد 1390, 10:49 صبح
دستورات به ترتيب اجرا مي شوند ولي سيستم فرصت نمي کند تغييرات شما را بلافاصله در ui برنامه تان اعمال کند چون messagebox جلوي آن را مي گيرد.
تابع زير معادل دستور doEvents در Winforms است.مي توني ان رو بعد از خط 4 قرار بده.

public void DoEvents()
{
// Create new nested message pump.
System.Windows.Threading.DispatcherFrame nestedFrame = new System.Windows.Threading.DispatcherFrame();

// Dispatch a callback to the current message queue, when getting called,
// this callback will end the nested message loop.
// note that the priority of this callback should be lower than the that of UI event messages.
System.Windows.Threading.DispatcherOperation exitOperation =
System.Windows.Threading.Dispatcher.CurrentDispatc her.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Backgr ound,
new System.Windows.Threading.DispatcherOperationCallba ck(delegate(Object state)
{
System.Windows.Threading.DispatcherFrame frame = state as System.Windows.Threading.DispatcherFrame;

// Exit the nested message loop.
frame.Continue = false;
return null;
}),
nestedFrame);

// pump the nested message loop, the nested message loop will
// immediately process the messages left inside the message queue.
System.Windows.Threading.Dispatcher.PushFrame(nest edFrame);

// If the "exitFrame" callback doesn't get finished, Abort it.
if (exitOperation.Status != System.Windows.Threading.DispatcherOperationStatus .Completed)
{
exitOperation.Abort();
}
}

water_lily_2012
سه شنبه 25 مرداد 1390, 13:55 عصر
سلام
اقای عربلو دستتون درد نکنه. حل شد.
فقط اگر لطف کنید یه توضیحی درباره کد های این تابع بدهید که چه طور عمل می کنند.