When there is an underscore in a label, WPF interprets it as an access key. One way to get around this is to use a double-underscore, which escapes the access character:
public string Name
{
get { return _name; }
set { _name = (value ?? "").Replace("_", "__");
}
private string _name;
Alternately: it is possible to turn off the access character for individual controls, using ContentPresenter.RecognizesAccessKey
. Unfortunately, to make use of this, you typically have to copy/modify the default control template and set any ContentPresenters' "RecognizesAccessKey" property to false. For Expander
, for example, you would have modify this part of the default template:
<ContentPresenter Grid.Column="1"
Margin="4"
ContentSource="Header"
RecognizesAccessKey="False" />
One more alternative (and actually probably the easiest). Use a TextBlock
for the header -- that will prevent the access key from being used:
<Expander IsExpanded="False">
<Expander.Header>
<TextBlock Text="{Binding Name}" />
</Expander.Header>
</Expander>
Related Questions