Post navigation ← Using the ultrasound sensor HC SR04 WPF Controls and Virtualization → This entry was posted in WPF on Novemby purpleblob. Seems I did need to handle resizing of the PlacementTarget so I’ve now added the following to the OnAttached methodĪssociatedObject.LayoutUpdated += (sender, e) => Update() I’ll leave those changes until I need them… Also my requirement doesn’t include the resizing of the PlacementTarget. Also the above code does not handle the Popup repositioning in the PlacementRectangle is used. This code could be improved by checking the Placement and ensuring it changes – in the code above I simply set to PlacementMode.Relative because I know my code a different PlacementMode. Then when we reset the placement to our original placement, the Popup position is recalculated. To get the Popup to recalculate its position we need to change the placement to something other than what it’s set as, i.e. On each WM_MOVEING message, we update the placement of the popup. When the AssociatedObject is loaded we locate the topmost window hosting the AssociatedObject and then we hook into the message queue watching for the Window WM_MOVEING message. So to use the above code we simple use the following XAML within a popup element force the popup to update it's positionĪssociatedObject.Placement = PlacementMode.Relative Private IntPtr HwndMessageHook(IntPtr hWnd, Var hwndSource = HwndSource.FromHwnd(helper.Handle) Var helper = new WindowInteropHelper(root) Var root = GetTopmostParent(AssociatedObject.PlacementTarget) as Window Private DependencyObject GetTopmostParent(DependencyObject element)Ĭurrent = (current is Visual || current is Visual3D) ?ĪssociatedObject.Loaded += (sender, e) => Public class AutoRepositionPopupBehavior : Behavior So I’ve implemented the following behavior to automatically reposition the popup when the parent window is moved I wanted a means to automatically reposition a popup in relation to it’s placement target – for example I created a popup that was displayed to the right of another control (the placement target), but when the control’s parent window moved the popup (by default) does not move with it – I needed it to reposition in relation to the placement target.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |