I'm trying to implement contextual help, when a button in the Ribbon Class has been selected. Try as I might, I can't seem to get the button firing on the Application Help command via this binding:
CommandManager.RegisterClassCommandBinding(typeof(UIElement), new CommandBinding(ApplicationCommands.Help, new ExecutedRoutedEventHandler(ShowHelpExecuted),
new CanExecuteRoutedEventHandler(ShowHelpCanExecute)));
I've even tried this:
CommandManager.RegisterClassCommandBinding(typeof(**RibbonToggleButton**), new CommandBinding(ApplicationCommands.Help, new ExecutedRoutedEventHandler(ShowHelpExecuted),
new CanExecuteRoutedEventHandler(ShowHelpCanExecute)));
For a direct binding to the button class, but I still don't get called when the Help (F1) button is called.
What does happen is the method is invoked, but the sender of the method is the main from that the control resides on, rather than the actual button that has focus. I want to provide help specific to the control that has focus (in this case the button), rather than just the form that the button resides on.
Here's a portion of the XML for the ribbon until the first toggle button
<Grid Name="GridRibbonBar"
Grid.Row="0"
Grid.Column="0"
IsHitTestVisible="True">
<Ribbon x:Name="RibbonMain"
Background="AliceBlue"
ContextMenu="{x:Null}"
PreviewMouseLeftButtonDown="RibbonMain_OnPreviewMouseLeftButtonDown"
ShowQuickAccessToolBarOnTop="False">
<Ribbon.TitleTemplate>
<DataTemplate>
<TextBlock TextAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="SemiBold"
Width="{Binding ElementName=Window, Path=ActualWidth}"
Text="{x:Static p:Resources.Title}">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="0"
Color="MintCream "
BlurRadius="10" />
</TextBlock.Effect>
</TextBlock>
</DataTemplate>
</Ribbon.TitleTemplate>
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu Visibility="Collapsed" />
</Ribbon.ApplicationMenu>
<!--Options Tab-->
<RibbonTab Header="{x:Static p:Resources.treeHdrOptions}"
ContextMenu="{x:Null}">
<RibbonGroup Header="{x:Static p:Resources.ribbonGroupGuestAccount}"
Visibility="{Binding Path=LoginViewModel.User.IsOwnerOrPowerOfAttorney,Converter={StaticResource VisibilityConverter},Source={StaticResource ViewModelLocatorService}}"
ContextMenu="{x:Null}">
<RibbonGroup.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"
Width="50" />
</ItemsPanelTemplate>
</RibbonGroup.ItemsPanel>
<RibbonToggleButton Name="guestacount"
Visibility="{Binding Path=LoginViewModel.User.IsOwnerOrPowerOfAttorney,Converter={StaticResource VisibilityConverter},Source={StaticResource ViewModelLocatorService}}"
Label="{x:Static p:Resources.treeGuest}"
SmallImageSource="../images/RibbonIcons/PNGFormat/GeneralGuest.png"
LargeImageSource="../images/RibbonIcons/PNGFormat/GeneralGuest.png"
Checked="RibbonToggleButton_OnChecked"
ContextMenu="{x:Null}" />
</RibbonGroup>
</RibbonTab>
Aucun commentaire:
Enregistrer un commentaire