#839 – A Label’s Target Could Have Its Own Label

You typically set the Target of a Label to a control that doesn’t have its own label.  The purpose is that when the user presses the Label’s access key, the target control will receive focus.

There’s nothing preventing you, however, from specifying the Target as a control that would normally have its own caption.

For example, you normally set a Button’s access key to one of the characters in its Content property–i.e. the text that appears on the face of the button.  In the example below, however, we use a Label to specify an access key for the Button, since the button’s content is just an asterisk character.  When you press the Label’s access key, the Button will activate.

    <StackPanel Orientation="Horizontal">
        <Label Content="_Calculate" VerticalAlignment="Center"
               Target="{Binding ElementName=btnCalc}"/>
        <Button Name="btnCalc" Content="*" VerticalAlignment="Center"
                Padding="10,5" Click="btnCalc_Click"/>
    </StackPanel>

839-001
839-002

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #839 – A Label’s Target Could Have Its Own Label

  1. Pingback: Dew Drop – June 11, 2013 (#1,565) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: