I have the following code from inside the UserControl.cs:
public void wait()
{
int i = 0;
while (i < 10)
{
i++;
System.Threading.Thread.Sleep(1000);
}
}
private void IsLoaded(object sender, RoutedEventArgs e)
{
wait();
}
I just want to wait 10 seconds AFTER the layout is rendered(you can see the buttons).
If i execute the code now, it will first wait 10 seconds and then it will render the layout.
I already tried with IsLoaded event for UserControl as you can see in the text and it is not working.
Loading
Sam HobbsPosted Feb 10, 2012, 4:06 AM
Whoever said that you should not use a timer is giving good advice. I sure agree. I agree that there is a more appropriate solution.
I think the problem is easily solved as soon as it is properly understood by someone experienced with Windows and .Net programming. I am confident I can help but I am having difficulty understanding what you need. It is getting late on my side of the world but it is early enough on your side of the world that you will have many others to help you.
Razvan AdrianPosted Feb 10, 2012, 3:41 AM
Basically what I am trying to do is to update a UserControl TextBlock, from the MainWindow.
Let's say I have a MainWindow and 2 UserControls. I can move from one UserControl to the other by using a method implemented in the MainWindow. The problem is that when I want to update a TextBlock inside the UserControl I got the update done after all the code in the MainWindow is executed.
What I want is to be able to update the UI immediately because the delay(1-2 seconds) is unacceptable.
I got so far the following answers:
"You should be updating the
textboxusing Binding andINotifyPropetyChanged(not with a timer).The UI should update automatically when the end of the method is hit.
Using a timer is not the right way to refresh your UI."
and
Right now I am testing both answers to see which one suits me. Maybe you have another idea.
Thank you for your time,
Adrian
Sam HobbsPosted Feb 10, 2012, 3:07 AM
Razvan AdrianPosted Feb 10, 2012, 2:37 AM
First of all I want to thank you for your fast answer.
Now, the question I asked was in another context. The real situation is like this:
I have a Window from where I render different(Children.Add(UserControl)) UserControls after doing different calculations in the MainWindow.
The problem is that when I try to update a TextBlock from one of the UserControls by using a Method from the parent Window, the visual update(the text being modified) takes place at the end of the method. And because the operations inside the method takes a few second, a lag between action and display appears.
I have tried: UpdateLayou() after updating but it is not working.
Is there any possible way to render a UserControl immediately after I update one of its fields ?
I need to work using this architecture because I work with Windows Messages in WndProc.
If you don't understand what I need I will make a new example tomorrow and I will paste you the code itself.
Sam HobbsPosted Feb 10, 2012, 2:22 AM
Please tell us what you need to do, without telling us how you think you need to do it. Tell us what the user should see.