How to: Create an ElementName Data Binding
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
You can bind an element's property value to a property on another named element by using the WPF Designer for Visual Studio. For example, you can bind a control's Background property to the Background property of its parent element.
To create a data binding to a named element
Create a new WPF Application project in Visual Basic or Visual C# named DataBindingDemo. For more information, see How to: Create a New WPF Application Project.
MainWindow.xaml opens in the WPF Designer.
In Design view, right-click the root Grid control and select Properties from the shortcut menu.
At the top of the Properties window, click in the Name box, type rootGrid, and press Enter to name the Grid control.
In the Properties window, locate the Background property.
Use the brush editor to create and assign a brush to the Background property. For more information, see How to: Create a Brush by Using the Brush Editor.
From the Toolbox, drag a ListBox control into the Grid control.
In the Properties window, locate the ListBox control's Background property.
Click the Inheritance property marker ().
Click Apply Data Binding.
The data binding builder appears.
On the Source pane in the left panel, click ElementName.
In the middle panel, click rootGrid.
Click the Path pane.
On the Path pane in the left panel, click the Background property.
The ListBox control's Background property is bound to the grid control's Background property.
Click outside the data binding builder to close the builder.
In XAML view, note the markup extension that was added for the Background property.
Background="{Binding ElementName=rootGrid, Path=Background}"