WPF 全屏时,程序运行和鼠标运动很慢的问题
<Window x:Class="WpfApp.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"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
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"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
启动动画,程序运行很慢,鼠标的运动很慢
解决方案 :
在XAML的Window属性中WindowStyle保留其默认值,
在窗口的加载响应函数里直接用了Win32 API函数来修改窗口的Style
这个是在网上找到的暂时解决方案
<Window x:Class="WpfApp.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"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowState="Maximized"
Topmost="True"
Loaded="OnMainLoad"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
private void OnMainLoad(object sender, RoutedEventArgs e)
{
int nStyle = Win32API.GetWindowLong(new WindowInteropHelper(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;
{
int nStyle = Win32API.GetWindowLong(new WindowInteropHelper(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;
版权声明:本文原创发表于 博客园,作者为 imbob,博客 http://imbob.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。