Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Internal / Commands / CommandHelpers.cs / 1 / CommandHelpers.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Security; using System.Security.Permissions; namespace MS.Internal.Commands { internal static class CommandHelpers { internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, params InputGesture[] inputGestures) { RegisterCommandHandler(controlType, command, executedRoutedEventHandler, null, inputGestures); } internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, Key key, ModifierKeys modifierKeys, ExecutedRoutedEventHandler executedRoutedEventHandler, CanExecuteRoutedEventHandler canExecuteRoutedEventHandler) { RegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, new KeyGesture(key, modifierKeys)); } internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, CanExecuteRoutedEventHandler canExecuteRoutedEventHandler, params InputGesture[] inputGestures) { // Validate parameters Debug.Assert(controlType != null); Debug.Assert(command != null); Debug.Assert(executedRoutedEventHandler != null); // All other parameters may be null // Create command link for this command CommandManager.RegisterClassCommandBinding(controlType, new CommandBinding(command, executedRoutedEventHandler, canExecuteRoutedEventHandler)); // Create additional input binding for this command for (int i = 0; i < inputGestures.Length; i++) { CommandManager.RegisterClassInputBinding(controlType, new InputBinding(command, inputGestures[i])); } } internal static bool CanExecuteCommandSource(ICommandSource commandSource) { ICommand command = commandSource.Command; if (command != null) { object parameter = commandSource.CommandParameter; IInputElement target = commandSource.CommandTarget; RoutedCommand routed = command as RoutedCommand; if (routed != null) { if (target == null) { target = commandSource as IInputElement; } return routed.CanExecute(parameter, target); } else { return command.CanExecute(parameter); } } return false; } ////// Executes the command on the given command source. /// ////// Critical - calls critical function (ExecuteCommandSource) /// TreatAsSafe - always passes in false for userInitiated, which is safe /// [SecurityCritical, SecurityTreatAsSafe] internal static void ExecuteCommandSource(ICommandSource commandSource) { CriticalExecuteCommandSource(commandSource, false); } ////// Executes the command on the given command source. /// ////// Critical - sets the user initiated bit on a command, which is used /// for security purposes later. It is important to validate /// the callers of this, and the implementation to make sure /// that we only call MarkAsUserInitiated in the correct cases. /// [SecurityCritical] internal static void CriticalExecuteCommandSource(ICommandSource commandSource, bool userInitiated) { ICommand command = commandSource.Command; if (command != null) { object parameter = commandSource.CommandParameter; IInputElement target = commandSource.CommandTarget; RoutedCommand routed = command as RoutedCommand; if (routed != null) { if (target == null) { target = commandSource as IInputElement; } if (routed.CanExecute(parameter, target)) { routed.ExecuteCore(parameter, target, userInitiated); } } else if (command.CanExecute(parameter)) { command.Execute(parameter); } } } // This allows a caller to override its ICommandSource values (used by Button and ScrollBar) internal static void ExecuteCommand(ICommand command, object parameter, IInputElement target) { RoutedCommand routed = command as RoutedCommand; if (routed != null) { if (routed.CanExecute(parameter, target)) { routed.Execute(parameter, target); } } else if (command.CanExecute(parameter)) { command.Execute(parameter); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AppliedDeviceFiltersDialog.cs
- CompilationSection.cs
- ProfileGroupSettingsCollection.cs
- XpsSerializerWriter.cs
- ListViewCommandEventArgs.cs
- SqlError.cs
- ManagedIStream.cs
- NodeLabelEditEvent.cs
- RightsManagementUser.cs
- CharAnimationUsingKeyFrames.cs
- XmlText.cs
- UserControlBuildProvider.cs
- TabItemAutomationPeer.cs
- Listener.cs
- ImpersonationContext.cs
- DataGridViewColumnConverter.cs
- DesignBindingEditor.cs
- ServerIdentity.cs
- MasterPageBuildProvider.cs
- SuspendDesigner.cs
- MetadataArtifactLoaderCompositeFile.cs
- RestHandlerFactory.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- PopupRoot.cs
- MediaContext.cs
- ServicePointManagerElement.cs
- EntityContainerEmitter.cs
- RowVisual.cs
- ManifestResourceInfo.cs
- XmlDeclaration.cs
- ActiveXHelper.cs
- ToolStripOverflowButton.cs
- AccessDataSourceView.cs
- FindCriteriaCD1.cs
- ThreadInterruptedException.cs
- OdbcConnectionString.cs
- MimeTypePropertyAttribute.cs
- XamlSerializerUtil.cs
- SqlCacheDependency.cs
- CompilerTypeWithParams.cs
- XpsPartBase.cs
- unsafeIndexingFilterStream.cs
- InternalsVisibleToAttribute.cs
- OdbcException.cs
- SmtpReplyReaderFactory.cs
- WebPartMinimizeVerb.cs
- RoutedPropertyChangedEventArgs.cs
- WindowProviderWrapper.cs
- JavaScriptObjectDeserializer.cs
- XmlTextAttribute.cs
- ChildDocumentBlock.cs
- Input.cs
- CompositeActivityTypeDescriptorProvider.cs
- LinqDataSourceSelectEventArgs.cs
- AnnouncementInnerClient11.cs
- TrustSection.cs
- hresults.cs
- FixedSchema.cs
- MessageDirection.cs
- HtmlTernaryTree.cs
- ConfigUtil.cs
- DataBoundLiteralControl.cs
- IsolatedStorageFile.cs
- UnauthorizedAccessException.cs
- AssemblyLoader.cs
- TargetPerspective.cs
- SecurityPermission.cs
- EntityConnection.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- IdentityNotMappedException.cs
- SystemFonts.cs
- ArraySubsetEnumerator.cs
- NameScopePropertyAttribute.cs
- FileEnumerator.cs
- NavigatorInput.cs
- WebPartCancelEventArgs.cs
- SocketInformation.cs
- BuildProvider.cs
- DbConnectionClosed.cs
- WhitespaceRule.cs
- cookie.cs
- IndexedGlyphRun.cs
- DuplexSecurityProtocolFactory.cs
- documentation.cs
- ISAPIApplicationHost.cs
- TextContainerChangedEventArgs.cs
- GPPOINT.cs
- LayoutExceptionEventArgs.cs
- HttpStreamMessage.cs
- DNS.cs
- _PooledStream.cs
- ImagingCache.cs
- MasterPage.cs
- DataGridViewTextBoxEditingControl.cs
- SubMenuStyleCollection.cs
- Exceptions.cs
- HtmlValidatorAdapter.cs
- WindowsAuthenticationEventArgs.cs
- PathGeometry.cs
- DoubleAverageAggregationOperator.cs