Assigning a Name to a Silverlight Element

Assigning a Name to a Silverlight Element

  • Comments 1

I answered this in a comment earlier today but I figured this was something that deserved a post of its own. There seems to be some confusion around how to set the name (x:Name in XAML) of a Silverlight object in code. Here's how it's done:

object.SetValue(FrameworkElement.NameProperty, "objectName");

This has the same affect as setting x:Name in XAML. The name property is a dependancy property implemented by the FrameworkElement abstract base class. This class is inherited by most Silverlight elements.

Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post