1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Properties
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector
8 using System.Collections.Generic;
11 using System.Windows.Controls.Primitives;
12 using System.Windows.Input;
13 using System.Windows.Media;
14 using System.Activities.Presentation.PropertyEditing;
15 using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.Controls;
18 // Acrylic needs a way of knowing when we begin and end extended edit mode,
19 // so this class fires commands when those two events take place.
21 internal class PropertyContainerPopup : WorkaroundPopup
23 // these events allow Acrylic to implement its workaround for Avalon/MFC interop
24 // focus issues (WinOS bug # 1713206)
25 public static readonly RoutedCommand OnBeginExtendedEdit = new RoutedCommand("OnBeginExtendedEdit", typeof(PropertyContainerPopup));
26 public static readonly RoutedCommand OnEndExtendedEdit = new RoutedCommand("OnEndExtendedEdit", typeof(PropertyContainerPopup));
28 public static CustomPopupPlacementCallback RightAlignedPopupPlacement
30 get { return new CustomPopupPlacementCallback(PropertyContainerPopup.RightAlignedPopupPlacementCallback); }
33 protected override void OnOpened(EventArgs e)
35 // Fire OnBeginExtendedEdit command (for Acrylic)
36 PropertyContainer owningPropertyContainer = (PropertyContainer)this.GetValue(PropertyContainer.OwningPropertyContainerProperty);
37 PropertyContainerPopup.OnBeginExtendedEdit.Execute(this, owningPropertyContainer);
42 protected override void OnClosed(EventArgs e)
46 PropertyContainer owningPropertyContainer = (PropertyContainer)this.GetValue(PropertyContainer.OwningPropertyContainerProperty);
48 // Revert back to Inline when the popup is dismissed and we haven't already switched
50 if (owningPropertyContainer != null && owningPropertyContainer.ActiveEditMode == PropertyContainerEditMode.ExtendedPopup)
52 DependencyObject potentialDescendant = Mouse.Captured as DependencyObject;
53 if (potentialDescendant != null && owningPropertyContainer.IsAncestorOf(potentialDescendant))
55 // v1 38479: This is a mitigation for Windows OS Bug 1965872.
56 // Here we force any control which has capture to lose it, though
57 // this situation can occur in other cases (e.g. via extensibility) but this covers the most
58 // common cases and is a safe fix.
62 owningPropertyContainer.ActiveEditMode = PropertyContainerEditMode.Inline;
65 // Fire OnEndExtendedEdit command (for Acrylic)
66 OnEndExtendedEdit.Execute(this, owningPropertyContainer);
69 public static CustomPopupPlacement[] RightAlignedPopupPlacementCallback(Size popupSize, Size targetSize, Point offset)
71 return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(targetSize.Width - popupSize.Width, targetSize.Height), PopupPrimaryAxis.Horizontal) };