--- title: "How to: Define a Name Scope" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "name scope [WPF], defining" - "Storyboards [WPF], animating in procedural code" - "animation [WPF], Storyboards [WPF], in procedural code" ms.assetid: 4f361925-6a08-40dc-8231-a61111c6b28b --- # How to: Define a Name Scope To animate with in code, you must create a and register the target objects' names with the element that owns that name scope. In the following example, a is created for `myMainPanel`. Two buttons, `button1` and `button2`, are added to the panel, and their names registered. Several animations and a are created. The storyboard's method is used to start the animations. Because `button1`, `button2`, and `myMainPanel` all share the same name scope, any one of them can be used with the method to start the animations. ## Example [!code-csharp[StoryboardBeginAnimation_procedural_snip#NameScopeExample](~/samples/snippets/csharp/VS_Snippets_Wpf/StoryboardBeginAnimation_procedural_snip/CSharp/ScopeExample.cs#namescopeexample)] [!code-vb[StoryboardBeginAnimation_procedural_snip#NameScopeExample](~/samples/snippets/visualbasic/VS_Snippets_Wpf/StoryboardBeginAnimation_procedural_snip/visualbasic/scopeexample.vb#namescopeexample)] ## See also - [Animate a Property by Using a Storyboard](how-to-animate-a-property-by-using-a-storyboard.md) - [Animation Overview](animation-overview.md)