我創建了一個帶有WPF(C#和XAML)的記分板應用程序,當我通過複選框對其啓用鎖定時,我需要使一個窗口完全無響應。意思是你不能點擊它,光標不會改變,特別是當你點擊它時窗口任務欄不會出現。這個記分牌是在一個遊戲的頂部,記分牌是最上面的窗口,但由於某種原因,我不能使它完全無法點擊。WPF Window unclickable
我試過IsHitTestVisible,Focusable,IsManipulationEnabled,ResizeMode,WindowStyle並將它們全部設置爲false,沒有任何效果。我仍然可以點擊窗口,它會彈出窗口的任務欄,當你有一個應該是全屏窗口的遊戲時,它會變得煩人。
我該怎麼辦?
更新:
找到了答案,通過改變一些谷歌的搜索詞。
的Win32類
//Rest of this code in located in the class itself
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int GWL_EXSTYLE = (-20);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hwnd,
int index);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hwnd,
int index, int newStyle);
public static void makeTransparent(IntPtr hwnd)
{
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
Win32.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
public static void makeNotTransparent(IntPtr hwnd)
{
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
Win32.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle^WS_EX_TRANSPARENT);
}
事件
base.OnSourceInitialized(e);
IntPtr hwnd = new WindowInteropHelper(yourWindow).Handle;
Win32.makeTransparent(hwnd);
我不知道一個單獨的計分板的想法。爲什麼不創建一個像大多數遊戲一樣繪製到遊戲窗口的圖像?或者我錯過了一些觀點? – ChiefTwoPencils
我有同樣的問題。我想當用戶右鍵單擊不可打開的窗口時,窗口(或桌面)在它後面對這個事件作出反應。如果我們使用其他平臺,比如Linux或Mac-OS,該怎麼辦? – Erfankam