Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 1.88 KB

how-to-define-a-name-scope.md

File metadata and controls

28 lines (22 loc) · 1.88 KB
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
csharp
vb
name scope [WPF], defining
Storyboards [WPF], animating in procedural code
animation [WPF], Storyboards [WPF], in procedural code
4f361925-6a08-40dc-8231-a61111c6b28b

How to: Define a Name Scope

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.

Example

[!code-csharpStoryboardBeginAnimation_procedural_snip#NameScopeExample] [!code-vbStoryboardBeginAnimation_procedural_snip#NameScopeExample]

See also