locked
FindName from a derived class RRS feed

  • Question

  • Hi,

     I'm creating a class that's derived from System.Windows.Controls.Page.

    I use this class to create my navigation pages.

    In this class I need to use FindName on the original page. I'm using the original pages Dispatcher to invoke the FindName call but I need to get the result of the findname synchronously. In my case I'm not getting the result immediately.

    What can I do to get the FindName result immediately?


    Regards

    Wednesday, November 25, 2009 9:49 AM

Answers

  •  The cross-thread exception is what I wanted to avoid.

    My call is the FrameWorkElement.FindName, you're right.

    I have a dll with a class that's deriving from System.Windows.Controls.Page. My Navigation pages in my Silverlight project are deriving from that new class. So I need to use FindName on the dll class to find controls on the Navigation page to manipulate these controls.

    I used SynchronizationContext.Send because I need the controls immediately without asynchronous queries.

    Everything works even if it seems difficult to understand. Thank you.

    Thursday, November 26, 2009 8:02 AM

All replies

  • In this class I need to use FindName on the original page.
     


    What do you mean by "original page"?


    Also, why are you using the Dispatcher here?  Are you needing to call FindName from a thread other than the UI thread?

    Wednesday, November 25, 2009 2:40 PM
  •  By original page I mean my codebehind that's deriving from my new class.

     

    Yes, I need to call FindName from a DLL.

    Does SynchronizationContext.Send work here?

    Thursday, November 26, 2009 3:17 AM
  • Does SynchronizationContext.Send work here?

     

    Ok, I'm lost.

    What FindName are you referring to?

    FrameworkElement.FindName, which is the only FindName method I can find relevant to the Page class, can be called directly from your derived class, because your derived class IS a FrameworkElement.


    Calling from a DLL is not the same as calling from a different thread, so I still don't see why you're asking about dispatchers and SynchronizationContext.  If you don't know if you're calling from another thread, then just call FindName().  If there's a cross-thread issue you'll get an appropriate exception.

     

    Thursday, November 26, 2009 7:52 AM
  •  The cross-thread exception is what I wanted to avoid.

    My call is the FrameWorkElement.FindName, you're right.

    I have a dll with a class that's deriving from System.Windows.Controls.Page. My Navigation pages in my Silverlight project are deriving from that new class. So I need to use FindName on the dll class to find controls on the Navigation page to manipulate these controls.

    I used SynchronizationContext.Send because I need the controls immediately without asynchronous queries.

    Everything works even if it seems difficult to understand. Thank you.

    Thursday, November 26, 2009 8:02 AM