Team Foundation Server Hosting
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » WPF » How can I find out that a UserControl is Rendered ?
       
Author Reply
Razvan Adrian
posted 3 posts
since Aug 18, 2010 
from Bucharest, Romania

How can I find out that a UserControl is Rendered ?

  Posted on: 09 Feb 2012       
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.
Sam Hobbs
posted  6490 posts
since  Sep 07, 2009 
from  Los Angeles, California, USA

 Re: How can I find out that a UserControl is Rendered ?
  Posted on: 10 Feb 2012        0  
I think you are asking the wrong question.

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.
Thinking is a feeling; pleasant for some and unpleasant for others.
Razvan Adrian
posted  3 posts
since  Aug 18, 2010 
from  Bucharest, Romania

 Re: How can I find out that a UserControl is Rendered ?
  Posted on: 10 Feb 2012        0  

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 Hobbs
posted  6490 posts
since  Sep 07, 2009 
from  Los Angeles, California, USA

 Re: How can I find out that a UserControl is Rendered ?
  Posted on: 10 Feb 2012        0  
Please, please, please explain what you need to happen, not how you think it needs to be done. Please try to do that. I really think sample code for this is very likely to be the less effective way to communicate.
Thinking is a feeling; pleasant for some and unpleasant for others.
Razvan Adrian
posted  3 posts
since  Aug 18, 2010 
from  Bucharest, Romania

 Re: How can I find out that a UserControl is Rendered ?
  Posted on: 10 Feb 2012        0  
Sam,

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 textbox using Binding and INotifyPropetyChanged (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

void MainWindow_Loaded(object sender, RoutedEventArgs e)         {             Task.Factory.StartNew(() => { Thread.Sleep(100); }).ContinueWith(r => { wait(); });         }
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 Hobbs
posted  6490 posts
since  Sep 07, 2009 
from  Los Angeles, California, USA

 Re: How can I find out that a UserControl is Rendered ?
  Posted on: 10 Feb 2012        0  
I am nearly certain that Sleep will not help since it will put the entire thread to sleep and therefore won't accomplish anything.

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.
Thinking is a feeling; pleasant for some and unpleasant for others.
       
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved