This topic has not yet been rated - Rate this topic

Label.Target Property

Gets or sets the element that receives focus when the user presses the label's access key.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[TypeConverterAttribute(typeof(NameReferenceConverter))]
public UIElement Target { get; set; }
<Label Target="nameOfExistingElement"/>

XAML Values

nameOfExistingElement

The name of UIElement that receives focus when the access key is pressed.

Property Value

Type: System.Windows.UIElement
The UIElement that receives focus when the user presses the access key. The default is null.

Identifier field

TargetProperty

Metadata properties set to true

None

You can provide keyboard shortcuts to elements that don't support access keys by giving a Label an access key and setting this property. Assign an access key to a label by placing an underscore immediately before the character that acts as the access key. An access key can be specified in the Content property or by setting Content to an AccessText object.

You cannot use this property to define a UIElement. For example, the following compiles but is not functional: <object.Target><UIElement../></object.Target>. This property provides a reference to an element that is already defined in your application.

The following example shows how to set the Target property of a Label.


<TextBox Name="tb" Width="50"/>
<Label Target="{Binding ElementName=tb}">_File</Label>


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Example is correct for WPF 4

The example in the topic is correct if you target WPF 4.

You can also use the x:Reference markup extension in WPF 4.

<Label Target="{x:Reference tb}">_File</Label>


If you use an earlier version of WPF, you need to use binding:
<Label Target="{Binding ElementName=tb}">_File</Label>

In WPF 4 it can be done via the x:Reference markup-extension
<Label Content="_Surname:" Target="{x:Reference surnameTextBox}" />
<TextBox x:Name="surnameTextBox" />
Needs binding?
Shouldn't this be:
            <Label Target="{Binding ElementName=tb}">_File</Label>