使用WPF的PopUp類實現父子視窗關聯

2021-10-25 08:04:05 字數 831 閱讀 1577

一、popup視窗可以顯示在螢幕任何地方,它們一般沒有父視窗,但是如果明確呼叫setparent,這類視窗也可以有父視窗。

[dllimport("user32.dll", entrypoint = "setparent")]

public static extern int setparent(intptr hwndchild, intptr hwndnewparent);

這樣設定之後,popup視窗會做為子視窗嵌入進父視窗內。從效果上來看,幾乎不再有popup的特性(如:觸及螢幕邊界時,也不會保持在螢幕中顯示的狀態)。

二、popup視窗也可以設定所有者視窗(owner),這時的popup視窗會保持其特有的屬性。同是也會跟隨其所有者視窗的z序顯示。

[dllimport("user32.dll", setlasterror = true)]

static extern int setwindowlong(intptr hwnd, int nindex, intptr dwnewlong);

windowinterophelper helper = new windowinterophelper(this.hostwindow);

setwindowlong(nowhwnd, -8, helper.handle.toint32());

因為popup的預設屬性是topmost的,如果因為需要將其設定為非topmost的狀態,則很容易出現popup視窗被其它視窗遮擋的問題。原因就是因為popup視窗並沒有所有者視窗,這時,其z序很容易被其它視窗壓到底下。如果在設定非topmost 屬性的同時,設定其所有者視窗,則可以解決這樣的問題。

WPF 使用Popup控制項做浮窗 提示框

需求 當滑鼠移入某個區域時,彈出乙個浮窗,以便使用者進行下一步操作。效果如下圖 當滑鼠移入左上角的 多選顯示 框內,出現下面的浮窗 懸浮在原ui之上 當在浮窗外點選滑鼠左鍵時,隱藏該浮窗。前台布局 borderbrush black width 60 height 40 margin 5 borde...

php 父類Model實現

class model public function set k v public function get k 指定查詢條件 例 array cat id 3,price 5 對應sql條件為cat id 3 and price 5 param array cond return void pu...

Popup視窗訪問父視窗的方法以及相互傳值

owner屬性 mx.core.uicomponent.owner value displayobjectcontainer void 此 ivisualelement 物件的所有者。預設情況下,它是此 ivisualelement 物件的父代。不過,如果此 ivisualelement 物件是由其...