WPF自定義視窗最大化顯示工作列

2021-06-21 22:11:25 字數 2572 閱讀 7930

當我們要自定義wpf視窗樣式時,通常是採用設計視窗的屬性 windowstyle="none" ,然後為視窗自定義放大,縮小,關閉按鈕的樣式。

然而這樣的話,當通過**設定視窗(**如下)放大時,視窗會把工作列給遮檔住。

private void max_click(object sender, routedeventargs e)

else

}

這樣的問題想必也同樣困繞著你。下面可以通過採用win32程式設計的方式把工作列顯示出來。idea源於網路上的資料,如果你在其他地方找到類似的,那祝賀你!

首先你的視窗**檔案引用兩個命名空間:

using wininterop = system.windows.interop;

using system.runtime.interopservices;

this.sourceinitialized += new eventhandler(win_sourceinitialized);
void win_sourceinitialized(object sender, eventargs e)

private static system.intptr windowproc(

system.intptr hwnd,

int msg,

system.intptr wparam,

system.intptr lparam,

ref bool handled)

return (system.intptr)0;

}private static void wmgetminmaxinfo(system.intptr hwnd, system.intptr lparam)

marshal.structuretoptr(mmi, lparam, true);

}/// /// point aka pointapi

///

[structlayout(layoutkind.sequential)]

public struct point

}[structlayout(layoutkind.sequential)]

public struct minmaxinfo

;/// ///

[structlayout(layoutkind.sequential, charset = charset.auto)]

public class monitorinfo

/// win32

[structlayout(layoutkind.sequential, pack = 0)]

public struct rect

// abs needed for bidi os

}/// win32

public int height

}/// win32

public rect(int left, int top, int right, int bottom)

/// win32

public rect(rect rcsrc)

/// win32

public bool isempty

}/// return a user friendly representation of this struct

public override string tostring()

"; }

return "rect ";

}/// determine if 2 rect are equal (deep compare)

public override bool equals(object obj)

return (this == (rect)obj);

}/// return the hashcode for this struct (not garanteed to be unique)

public override int gethashcode()

/// determine if 2 rect are equal (deep compare)

public static bool operator ==(rect rect1, rect rect2)

/// determine if 2 rect are different(deep compare)

public static bool operator !=(rect rect1, rect rect2)

}[dllimport("user32")]

internal static extern bool getmonitorinfo(intptr hmonitor, monitorinfo lpmi);

/// ///

///

[dllimport("user32")]

internal static extern intptr monitorfromwindow(intptr handle, int flags);

#endregion

最後f5,你會看到你所期望效果。

WPF自定義視窗最大化顯示工作列

原文 wpf自定義視窗最大化顯示工作列 當我們要自定義wpf視窗樣式時,通常是採用設計視窗的屬性 windowstyle none 然後為視窗自定義放大,縮小,關閉按鈕的樣式。然而這樣的話,當通過 設定視窗 如下 放大時,視窗會把工作列給遮檔住。private void max click obje...

wpf 自定義視窗,最大化時不覆蓋工作列

相信很多人使用wpf時會選擇自定義美觀的視窗,因此會設定windowstyle none 取消自帶的標題欄。但這樣使用 windowstate maximized 或者後台 this.windowstate system.windows.windowstate.maximized 最大化視窗會覆蓋掉...

WPF視窗最大化 不覆蓋工作列

目的 讓視窗初始化時 最大化,只有最小化和關閉按鈕。許多軟體都是如此 分析 網上好多實現都是一大堆 直接使用win的api來獲取各種引數 實現 全屏設定 rect rc systemparameters.workarea 獲取工作區大小 this.left 0 設定位置 this.top 0 thi...