title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
---|---|---|---|---|---|---|---|---|---|---|
How to: Define a Name Scope |
Learn how to create a NameScope and define it by registering the target objects' names with the element that owns that name scope. |
03/30/2017 |
|
|
4f361925-6a08-40dc-8231-a61111c6b28b |
To animate with xref:System.Windows.Media.Animation.Storyboard in code, you must create a xref:System.Windows.NameScope and register the target objects' names with the element that owns that name scope. In the following example, a xref:System.Windows.NameScope is created for myMainPanel
. Two buttons, button1
and button2
, are added to the panel, and their names registered. Several animations and a xref:System.Windows.Media.Animation.Storyboard are created. The storyboard's xref:System.Windows.Media.Animation.Storyboard.Begin%2A 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 xref:System.Windows.Media.Animation.Storyboard xref:System.Windows.Media.Animation.Storyboard.Begin%2A method to start the animations.
[!code-csharpStoryboardBeginAnimation_procedural_snip#NameScopeExample] [!code-vbStoryboardBeginAnimation_procedural_snip#NameScopeExample]