mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +02:00
* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
26 lines
1.7 KiB
Markdown
26 lines
1.7 KiB
Markdown
---
|
|
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 <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-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)
|