Hello
I have encountered a Problem in the Ribbon Control concerning the Access Key ("_"). My texts containing the _ character are not correctly displayed, namely the first _ in the string is always missing (example: KRD_AZ_RDTZ_09 is displayed as KRDAZ_RDTZ_09). I would like to turn off the Recognition of the Access Key for the RibbonTabItem Control (and some other Controls;preferably for all Controls).
I managed to find a solution, which is not optimal IMO. That is using the default style of the Control, going through the XML to find the ContentPresenter and turning the RecognizeAccessKey Property off (setting it to false). With this I get the display I want but as said it is not optimal. I was also searching and exploring other ideas but I could not find any other way to affect this property.
I was therefore wondering if I missed something, can this "Feature" be turned of some how without overriding the default style? (Preferably for all Controls)
I am using the WPF 2012 Vol. 2 Controls.
Thanks in advance for your answer.
Regards BB
Sorry. I forgot that the default styles for the RibbonTabItem will strip out the mnemonics of the Header string because that is how Office behaves. It uses those mnemonics as the default keytip. It looks like you'll have to modify the string, change the default styles or just use a custom IValueConverter that will escape the mnemonics. For the latter you might even be able to use a utility method we have.
e.g.
public class EscapeMnemonicsConverter : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var strValue = value as string; if (strValue != null) return Infragistics.Windows.Utilities.StripMnemonics("_" + strValue, true); return Binding.DoNothing; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return Binding.DoNothing; } }
So then you'd define an instance of this converter in the resources and use that in your binding.
<igWpf:XamRibbon> <igWpf:XamRibbon.Resources> <local:EscapeMnemonicsConverter x:Key="escapeMnemonics" xmlns:local="clr-namespace:WpfApplication3" /> </igWpf:XamRibbon.Resources> <igWpf:RibbonTabItem Header="{Binding ItemName, Converter={StaticResource escapeMnemonics}}" /></igWpf:XamRibbon>
Thanks for the fast reply.
The option with the escape char is not acceptable in this case, since the strings displayed are loaded from an existing costumer DB with several 100K long lists (and manipulating the header text itself, before displaying it, is a workaround I simply want to avoid...).
I tried the DataTemplate option with two settings however neither worked (in both the _ was not displayed correctly):
Option one:
<igRibbon:RibbonTabItem Header="{Binding ItemName}">
<igRibbon:RibbonTabItem.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</igRibbon:RibbonTabItem.HeaderTemplate>
Option Two:
<TextBlock>
<ContentPresenter Content="{Binding}" RecognizesAccessKey="False"/>
</TextBlock>
Did I do a mistake perhaps?
As you noted you can change the styles so that the RecognizesAccessKey property of the ContentPresenter is set to false. There are a couple of other options. You can change your string so that it has two consecutive "_" underscores (i.e. escape the underscore). Another option might be to set the HeaderTemplate of the RibbonTabItem to a DataTemplate that just uses a TextBlock. Internally the ContentPresenter uses the RecognizesAccessKey to determine if it should create a TextBlock or an AccessText for the string it is representing (assuming it is a string and that string contains a mnemonic).