新聞中心
WPF全屏幕窗口在實際使用中是一個比較常見的應(yīng)用方法。如何才能快速簡單的實現(xiàn)這一功能,是一個初級開發(fā)人員必須掌握的技巧。#t#

創(chuàng)新互聯(lián)建站專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、陽明網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、電子商務(wù)商城網(wǎng)站建設(shè)、集團公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為陽明等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
WPF中用XAML創(chuàng)建WPF全屏幕窗口非常簡單,只需要簡單地設(shè)置Window元素的一些屬性即可:
- < Window x:Class=
"WindowsApp.Window1" - xmlns="http://schemas.
microsoft.com/winfx/2006/
xaml/presentation" - xmlns:x="http://schemas.
microsoft.com/winfx/2006/xaml" - WindowState="Maximized"
- Topmost="True"
- WindowStyle="None"
- AllowsTransparency="true"
- >
- < Grid>
- < !--忽略建立動畫的代碼-->
- < /Grid>
- < /Window>
最后程序的運行結(jié)果卻出乎所料,在調(diào)用Storyboard.Begin之前,一切都很正常,但是一旦啟動動畫,程序運行及很慢,鼠標(biāo)的運動很慢很慢。有興趣的朋友可以自己嘗試一下。
如果把窗口Style稍微修改,問題就得到了解決,把WindowStyle的None修改為其它的值似乎都可以正常運行。動畫的效率得到了極大的提高。
但是我們要的就是WPF全屏幕窗口,那怎么辦呢?時間比較緊急,咱就曲線救國繞過去吧!在XAML的Window屬性中WindowStyle保留其默認(rèn)值,在窗口的加載響應(yīng)函數(shù)里直接用了Win32 API函數(shù)來修改窗口的Style?,F(xiàn)在可以幾乎可以肯定這不像是正統(tǒng)的方法,或者還有其它的還沒有了解的知識。修改后的代碼如下:
- < Window x:Class="WindowsApp.
Window1"- xmlns="http://schemas.
microsoft.com/winfx/2006/
xaml/presentation"- xmlns:x="http://schemas.
microsoft.com/winfx/2006/xaml"- WindowState="Maximized"
- Topmost="True"
- Loaded="OnMainLoad"
- >
- < Grid>
- < !--忽略建立動畫的代碼-->
- < /Grid>
- < /Window>
- private void OnMainLoad
(object sender, Routed
EventArgs e)- {
- int nStyle = Win32API.
GetWindowLong(new WindowInterop
Helper(this).Handle;,Win32API.
GWL_STYLE);- nStyle &= ~Win32API.WS_CAPTION;
- Win32API.SetWindowLong
(new WindowInteropHelper(this).
Handle;, Win32API.GWL_STYLE, nStyle);- }
- public class Win32API
- {
- [DllImport("user32.dll")]
- public static extern int
SetWindowLong(IntPtr hWnd,
int nIndex, int New);- [DllImport("user32.dll")]
- public static extern int
GetWindowLong(IntPtr hWnd,
int nIndex);- }
- public const int GWL_STYLE = -16;
- public const int GWL_EXSTYLE = -20;
- public const int WS_CAPTION =
0x00C00000;
WPF全屏幕窗口的創(chuàng)建代碼中使用的WindowInteropHelper類將在后續(xù)的隨筆中介紹。至于用C#調(diào)用Win32 API函數(shù)應(yīng)該不需要進一步的介紹,不熟悉C#的朋友可以參考MSDN中的Interoperability相關(guān)內(nèi)容
當(dāng)前標(biāo)題:WPF全屏幕窗口創(chuàng)建方法介紹
當(dāng)前鏈接:http://fisionsoft.com.cn/article/cogjpgg.html


咨詢
建站咨詢
