Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / ExtensionWindowHeader.cs / 1305376 / ExtensionWindowHeader.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; //This class is visual representation of WindowHeader like control, which is used with ExtenstionWindows to allow //moving and closing. Actual moving logic is handled by ExtensionSurface class [TemplatePart(Name = "PART_Header")] [TemplatePart(Name = "PART_CloseButton")] class ExtensionWindowHeader : Control { public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(ExtensionWindowHeader)); public static readonly DependencyProperty ButtonCloseIconProperty = DependencyProperty.Register("ButtonCloseIcon", typeof(DrawingBrush), typeof(ExtensionWindowHeader)); public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(DrawingBrush), typeof(ExtensionWindowHeader)); public static readonly DependencyProperty DropDownMenuIconProperty = DependencyProperty.Register("DropDownMenuIcon", typeof(DrawingBrush), typeof(ExtensionWindowHeader)); Button closeButton; ExtensionWindow parent; ExtensionSurface surface; Point offset; [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, Justification = "Overriding metadata for dependency properties in static constructor is the way suggested by WPF")] static ExtensionWindowHeader() { DefaultStyleKeyProperty.OverrideMetadata( typeof(ExtensionWindowHeader), new FrameworkPropertyMetadata(typeof(ExtensionWindowHeader))); } public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } [Fx.Tag.KnownXamlExternal] public DrawingBrush ButtonCloseIcon { get { return (DrawingBrush)GetValue(ButtonCloseIconProperty); } set { SetValue(ButtonCloseIconProperty, value); } } [Fx.Tag.KnownXamlExternal] public DrawingBrush Icon { get { return (DrawingBrush)GetValue(IconProperty); } set { SetValue(IconProperty, value); } } [Fx.Tag.KnownXamlExternal] public DrawingBrush DropDownMenuIcon { get { return (DrawingBrush)GetValue(DropDownMenuIconProperty); } set { SetValue(DropDownMenuIconProperty, value); } } public override void OnApplyTemplate() { base.OnApplyTemplate(); this.closeButton = this.Template.FindName("PART_CloseButton", this) as Button; if (null != this.closeButton) { this.closeButton.Click += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e) { ExtensionWindow.RaiseWindowCloseEvent(this.parent); } ); } } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs args) { base.OnMouseLeftButtonDown(args); if (ExtensionSurface.PlacementMode.Absolute == ExtensionSurface.GetMode(this.parent)) { this.offset = Mouse.GetPosition(this); Mouse.OverrideCursor = Cursors.Arrow; CaptureMouse(); } } protected override void OnMouseMove(MouseEventArgs args) { base.OnMouseMove(args); if (args.LeftButton == MouseButtonState.Pressed && this.IsMouseCaptured) { Point moveTo = Mouse.GetPosition(this.surface); moveTo.Offset(-offset.X, -offset.Y); this.surface.SetWindowPosition(this.parent, moveTo); } } protected override void OnMouseLeftButtonUp(MouseButtonEventArgs args) { base.OnMouseLeftButtonUp(args); if (this.IsMouseCaptured) { Mouse.OverrideCursor = null; Mouse.Capture(null); } } protected override void OnVisualParentChanged(DependencyObject oldParent) { base.OnVisualParentChanged(oldParent); if (!DesignerProperties.GetIsInDesignMode(this) && !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface)) { Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow"); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; //This class is visual representation of WindowHeader like control, which is used with ExtenstionWindows to allow //moving and closing. Actual moving logic is handled by ExtensionSurface class [TemplatePart(Name = "PART_Header")] [TemplatePart(Name = "PART_CloseButton")] class ExtensionWindowHeader : Control { public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(ExtensionWindowHeader)); public static readonly DependencyProperty ButtonCloseIconProperty = DependencyProperty.Register("ButtonCloseIcon", typeof(DrawingBrush), typeof(ExtensionWindowHeader)); public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(DrawingBrush), typeof(ExtensionWindowHeader)); public static readonly DependencyProperty DropDownMenuIconProperty = DependencyProperty.Register("DropDownMenuIcon", typeof(DrawingBrush), typeof(ExtensionWindowHeader)); Button closeButton; ExtensionWindow parent; ExtensionSurface surface; Point offset; [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, Justification = "Overriding metadata for dependency properties in static constructor is the way suggested by WPF")] static ExtensionWindowHeader() { DefaultStyleKeyProperty.OverrideMetadata( typeof(ExtensionWindowHeader), new FrameworkPropertyMetadata(typeof(ExtensionWindowHeader))); } public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } [Fx.Tag.KnownXamlExternal] public DrawingBrush ButtonCloseIcon { get { return (DrawingBrush)GetValue(ButtonCloseIconProperty); } set { SetValue(ButtonCloseIconProperty, value); } } [Fx.Tag.KnownXamlExternal] public DrawingBrush Icon { get { return (DrawingBrush)GetValue(IconProperty); } set { SetValue(IconProperty, value); } } [Fx.Tag.KnownXamlExternal] public DrawingBrush DropDownMenuIcon { get { return (DrawingBrush)GetValue(DropDownMenuIconProperty); } set { SetValue(DropDownMenuIconProperty, value); } } public override void OnApplyTemplate() { base.OnApplyTemplate(); this.closeButton = this.Template.FindName("PART_CloseButton", this) as Button; if (null != this.closeButton) { this.closeButton.Click += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e) { ExtensionWindow.RaiseWindowCloseEvent(this.parent); } ); } } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs args) { base.OnMouseLeftButtonDown(args); if (ExtensionSurface.PlacementMode.Absolute == ExtensionSurface.GetMode(this.parent)) { this.offset = Mouse.GetPosition(this); Mouse.OverrideCursor = Cursors.Arrow; CaptureMouse(); } } protected override void OnMouseMove(MouseEventArgs args) { base.OnMouseMove(args); if (args.LeftButton == MouseButtonState.Pressed && this.IsMouseCaptured) { Point moveTo = Mouse.GetPosition(this.surface); moveTo.Offset(-offset.X, -offset.Y); this.surface.SetWindowPosition(this.parent, moveTo); } } protected override void OnMouseLeftButtonUp(MouseButtonEventArgs args) { base.OnMouseLeftButtonUp(args); if (this.IsMouseCaptured) { Mouse.OverrideCursor = null; Mouse.Capture(null); } } protected override void OnVisualParentChanged(DependencyObject oldParent) { base.OnVisualParentChanged(oldParent); if (!DesignerProperties.GetIsInDesignMode(this) && !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface)) { Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow"); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SocketElement.cs
- EncodingDataItem.cs
- BaseTemplateParser.cs
- CodeIndexerExpression.cs
- PagedDataSource.cs
- SafeLibraryHandle.cs
- MethodBody.cs
- WsdlHelpGeneratorElement.cs
- CopyNamespacesAction.cs
- ImageList.cs
- ErrorProvider.cs
- PolicyStatement.cs
- AlternateView.cs
- DataObjectFieldAttribute.cs
- Decoder.cs
- DbBuffer.cs
- TransformConverter.cs
- DesignerLoader.cs
- RegexCaptureCollection.cs
- Deflater.cs
- TableLayoutStyleCollection.cs
- TriggerAction.cs
- EntityDataSourceDataSelectionPanel.cs
- Tablet.cs
- RegistrationServices.cs
- MailWebEventProvider.cs
- ComPlusContractBehavior.cs
- PeerInvitationResponse.cs
- ServiceDesigner.xaml.cs
- GCHandleCookieTable.cs
- BooleanAnimationUsingKeyFrames.cs
- InputReportEventArgs.cs
- SafeNativeMethods.cs
- RadioButtonFlatAdapter.cs
- ThicknessKeyFrameCollection.cs
- LinqExpressionNormalizer.cs
- StoryFragments.cs
- SuppressIldasmAttribute.cs
- SerializableTypeCodeDomSerializer.cs
- ResolveCriteriaCD1.cs
- TypeBrowserDialog.cs
- entityreference_tresulttype.cs
- shaperfactory.cs
- InvokePattern.cs
- List.cs
- TableCellCollection.cs
- ProvidersHelper.cs
- ObjectPersistData.cs
- MILUtilities.cs
- ISO2022Encoding.cs
- PeerInvitationResponse.cs
- PageBuildProvider.cs
- BoundPropertyEntry.cs
- WebServiceClientProxyGenerator.cs
- InlinedLocationReference.cs
- DotNetATv1WindowsLogEntryDeserializer.cs
- ChangeBlockUndoRecord.cs
- MetadataCache.cs
- ExtensionDataObject.cs
- DataGridViewColumnConverter.cs
- HandleValueEditor.cs
- CapacityStreamGeometryContext.cs
- AesCryptoServiceProvider.cs
- Peer.cs
- BidPrivateBase.cs
- StylusPlugin.cs
- InternalMappingException.cs
- ImplicitInputBrush.cs
- SignedPkcs7.cs
- DataGridViewTextBoxColumn.cs
- SqlConnectionPoolProviderInfo.cs
- DataGridViewImageColumn.cs
- DeflateStream.cs
- ProtectedConfigurationSection.cs
- PropertyPathConverter.cs
- DataStorage.cs
- Lock.cs
- HuffmanTree.cs
- MetadataArtifactLoaderCompositeResource.cs
- GeneralTransformGroup.cs
- StringBlob.cs
- DuplexClientBase.cs
- CatalogPart.cs
- DataGridViewLinkColumn.cs
- VisualBasicDesignerHelper.cs
- AdornedElementPlaceholder.cs
- XamlDebuggerXmlReader.cs
- DataObjectPastingEventArgs.cs
- ObjectItemCachedAssemblyLoader.cs
- PackageRelationshipSelector.cs
- GreaterThan.cs
- StrongName.cs
- BitStream.cs
- TransformerInfo.cs
- SessionParameter.cs
- TrailingSpaceComparer.cs
- OneWayBindingElement.cs
- ProfileGroupSettingsCollection.cs
- MethodToken.cs
- MultiBindingExpression.cs