WPF中的固定窗口 [英] Immovable window in wpf
本文介绍了WPF中的固定窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用鼠标单击并拖动wpf窗口时将其设置为不可移动?
Hi How to set my wpf window as no movable when it is clicked and dragged using mouse?
推荐答案
尝试拦截此类呼叫;
Try intercepting the calls, like this;
using System;
using System.Windows;
using System.Windows.Interop;
namespace WpfApplication23
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SourceInitialized += Window1_SourceInitialized;
}
private void Window1_SourceInitialized(object sender, EventArgs e)
{
WindowInteropHelper helper = new WindowInteropHelper(this);
HwndSource source = HwndSource.FromHwnd(helper.Handle);
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
switch (msg)
{
case WM_SYSCOMMAND:
int command = wParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
{
handled = true;
}
break;
default:
break;
}
return IntPtr.Zero;
}
}
}
希望这会有所帮助,
Fredrik
Hope this helps,
Fredrik
将此添加到您的窗口Xaml ResizeMode ="NoResize"这将使用户无法确定窗口的大小,因为不确定该如何移动.
发现它添加IsDraggingOrResizing ="False"这应该可以解决问题!
等待,抱歉,没关系.这仅适用于DevExpress Windows ...
add this to your window Xaml ResizeMode="NoResize" this will disable the user from resizing the window as for the moving im not sure.
Found it add IsDraggingOrResizing="False" this should do the trick!
Wait sorry nevermind. This is only for DevExpress Windows...
这篇关于WPF中的固定窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文