locked
FindName and custom controls RRS feed

  • Question

  • I have a custom control (enterly C#, no XAML) which inherits from StackPanel and I can't do a FindName (always returns null). I have found some stuff about creating a namescope and stuff but it all tends to give me errors.  I have tried to create a namedscope in my control's constructor and register the controls I want to be able to find with it - no joy. I have attempted to register these controls with my parent - no joy.

     

    Does some one have a link or a page or something on how to make my control respect the FindName method?

     

    Thanks

     

    -Cam

    Tuesday, November 20, 2007 3:38 PM

Answers

  • Choose some object in your logical tree as the scope root. The control itself will do. Let's call it nameroot.

    Call NameScope.SetNameScope(nameroot, new NameScope());

    Register names of the objects with nameroot.RegisterName("SomeObjectName", someobject);

    Tuesday, November 20, 2007 4:50 PM

All replies

  • If the structure is fix you might get there using the VisualTreeHelper.

    Tuesday, November 20, 2007 4:24 PM
  • Choose some object in your logical tree as the scope root. The control itself will do. Let's call it nameroot.

    Call NameScope.SetNameScope(nameroot, new NameScope());

    Register names of the objects with nameroot.RegisterName("SomeObjectName", someobject);

    Tuesday, November 20, 2007 4:50 PM