When we set the popup's stayopen= "True", the popup does not move the position with it when the form is moved or the size of the form is changed. To solve this problem, you can define an additional property for the popup, as shown in the following code:
/// <summary>///Popup helper class, when you move a form or change the size of a form when the popup setting stayopen= "True", the popup does not move with the form/// </summary> Public classpopophelper{ Public StaticDependencyObject getpopupplacementtarget (DependencyObject obj) {return(DependencyObject) obj. GetValue (Popupplacementtargetproperty); } Public Static voidsetpopupplacementtarget (DependencyObject obj, DependencyObject value) {obj. SetValue (popupplacementtargetproperty, value); } Public Static ReadOnlyDependencyProperty Popupplacementtargetproperty =dependencyproperty.registerattached ("Popupplacementtarget",typeof(DependencyObject),typeof(Popophelper),NewPropertyMetadata (NULL, onpopupplacementtargetchanged)); Private Static voidonpopupplacementtargetchanged (DependencyObject D, DependencyPropertyChangedEventArgs e) {if(E.newvalue! =NULL) {DependencyObject popuppopupplacementtarget= E.newvalue asDependencyObject; Popup Pop= d asPopup; Window W=Window.getwindow (Popuppopupplacementtarget); if(NULL!=W) {//let the popup move as the form movesW.locationchanged + =Delegate { varMi =typeof(Popup). GetMethod ("updateposition", System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Instance); Oil Invoke (pop,NULL); }; //make the popup move position as the size of the form changesW.sizechanged + =Delegate { varMi =typeof(Popup). GetMethod ("updateposition", System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Instance); Oil Invoke (pop,NULL); }; } } }}
How to use:
<Popupx:name= "Part_popup"allowstransparency= "True"IsOpen= "True"Placement= "Bottom"Placementtarget="{Binding Elementname=part_togglebutton}"HorizontalOffset= "-5"ZUI:PopopHelper.PopupPlacementTarget="{Binding Elementname=part_togglebutton}"Staysopen= "True"> <Borderx:name= "Itemspresenter"Background= "Transparent"> <Itemspresenter/> </Border></Popup>
Reference Blog Address:
1, http://www.cnblogs.com/Leaco/p/3168540.html
2, http://www.cnblogs.com/xiaokang088/archive/2011/07/06/2099489.html
Solve the problem of popup not moving with window