WPF AccessText

WPF AccessText Control

The AccessText control in WPF converts a character preceded by an underscore to an Access Key. The Access Key is registered and therefore raises an event when pressed.

This article demonstrates how to create and use an AccessText control in WPF using XAML and C#.

Creating an AccessText

The AccessText element represents an AccessText control in XAML. 

<AccessText>_Click Me</AccessText> 

The following code snippet adds an AccessText to a Button control. The button control click event will be raised when you select the ALT+C keys on the keyboard.

<Button Name="Button1" Width="120" Height="50" Margin="33,70,59,124"
        FontSize="16" Click="Button1_Click">
    <AccessText>_Click Me</AccessText>
</Button>   

If there are multiple underscore characters, only the first one is converted into an AccessKey; the other underscores appear as normal text. If the underscore that you want converted to the access key is not the first underscore, use two consecutive underscores for any underscores that precede the one that you want to convert. 


Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.