You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C# WPF PRISM:如何让作为独立对话框的UserControl可拖拽?

实现独立对话框式UserControl的拖拽功能

你通过Prism DialogService打开的UserControl实际被包裹在Window容器中,可通过以下方式实现类似DragMove()的效果:

  • 在UserControl的MouseLeftButtonDown事件处理方法中,获取承载当前控件的Window实例,调用它的DragMove()方法:
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var parentWindow = Window.GetWindow(this);
    parentWindow?.DragMove();
}
  • 若只需点击特定区域(如自定义标题栏)触发拖拽,给目标区域绑定鼠标按下事件,在事件处理中执行上述逻辑即可。

这种方式本质是调用了承载UserControl的对话框Window的拖拽方法,完全等效于Window的DragMove()效果。

内容的提问来源于stack exchange,提问作者MaxB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 22:44:51