Programatically Setting the Name

Topics: Developer Forum, User Forum
Apr 24, 2007 at 11:44 AM
I'm creating instances of InteractiveVisual3D in code. If I create an instance in XAML I can set x:Name="my3DObject", for example, but how do I do this in code? :S

Thanks in advance,

Derek.
Sep 22, 2007 at 2:16 PM
Erm you could use the TAG values instead and reference those programmatically

or...

maybe its in the System.Windows.Markup.RuntimeNamePropertyAttribute area???

HTH

Si.
Sep 30, 2007 at 7:43 PM
Ok, This is it...

Namescopes and Name-related APIs
FrameworkElement has FindName, RegisterName and UnregisterName methods. If the element you call these methods on owns a namescope, the element methods simply call into the namescope methods. Otherwise, the parent element is checked to see if it owns a namescope, and this process continues recursively until a namescope is found (with one guaranteed to be at the root). FrameworkContentElement has analogous behaviors, with the exception that no FrameworkContentElement will ever own a namescope. The methods exist on FrameworkContentElement so that the calls can be forwarded eventually to a FrameworkElement parent element.

SetNameScope is used to map a new namescope to an existing object. You can call SetNameScope more than once in order to reset or clear the namescope, but that is not a common usage. Also, GetNameScope is not typically used from code.


Hope this helps...
Oct 20, 2007 at 8:57 PM
I have the same problem in naming the InteractiveVisual3D instance for using against Storeboard for animating it. So please can any one provide me with a sample code Or tell me what is the the problem?

the following is sample code of my user control:


InteractiveVisual3D currentInteractiveVisual3D = new InteractiveVisual3D();
currentInteractiveVisual3D.SetValue(FrameworkElement.NameProperty, "InteractiveVisual3D0");
NameScope.SetNameScope(this, new NameScope());
this.RegisterName("InteractiveVisual3D0" ,currentInteractiveVisual3D);
.........
Storyboard.SetTargetName(translaionAnimation, "InteractiveVisual3D0");
Storyboard.SetTargetProperty(translaionAnimation, new PropertyPath("(Visual3D.Transform).(Transform3DGroup.Children)4.(TranslateTransform3D.OffsetX)"));

storyboard.Children.Add(translaionAnimation);
storyboard.Begin(this);

Thanks a lot in advance