Skip to content

Commit aa9bba6

Browse files
committed
feat(Views): 实现全屏拖拽标记功能
- 新增 MarkerWindow 类,用于显示全屏标记 - 修改 MainWindow.xaml.cs 中的鼠标事件处理逻辑 -优化拖拽流程,确保标记跟随鼠标移动 - 添加屏幕边缘检测和标记窗口的显示/隐藏逻辑
1 parent 69f0c70 commit aa9bba6

File tree

3 files changed

+102
-17
lines changed

3 files changed

+102
-17
lines changed

Models/HolidayGreeter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


Views/MainWindow.xaml.cs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
using System.Windows.Controls;
1010
using System.Windows.Forms;
1111
using System.Windows.Input;
12-
using System.Windows.Media;
1312
using System.Windows.Navigation;
14-
using System.Windows.Shapes;
1513
using CallRecording.Models;
1614
using CallRecording.ViewModels;
1715
using Microsoft.Toolkit.Uwp.Notifications;
@@ -39,6 +37,7 @@ public partial class MainWindow : Window
3937

4038
// GlobalMVVM gmvvm = new GlobalMVVM();
4139
private bool isDragging = false;
40+
private MarkerWindow markerWindow;
4241

4342
string msg = "";
4443

@@ -247,8 +246,22 @@ private void MainWindow_Closing(object sender, CancelEventArgs e)
247246

248247
private void adm_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
249248
{
249+
// 确保之前的状态已清理
250+
if (markerWindow != null)
251+
{
252+
markerWindow.Close();
253+
markerWindow = null;
254+
}
255+
256+
// 重置拖拽状态
250257
isDragging = true;
251-
Mouse.Capture(sender as UIElement);
258+
var element = sender as UIElement;
259+
if (element != null)
260+
{
261+
element.CaptureMouse();
262+
}
263+
264+
e.Handled = true;
252265
}
253266

254267
private void adm_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
@@ -268,10 +281,26 @@ private void adm_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
268281
{
269282
if (isDragging)
270283
{
271-
// 右键取消拖拽
284+
// 完全重置拖拽状态
272285
isDragging = false;
286+
var element = sender as UIElement;
287+
if (element != null)
288+
{
289+
element.ReleaseMouseCapture();
290+
}
291+
273292
Mouse.Capture(null);
274293
DragFeedbackLayer.Children.Clear();
294+
295+
// 关闭标记窗口
296+
if (markerWindow != null)
297+
{
298+
markerWindow.Close();
299+
markerWindow = null;
300+
}
301+
302+
// 强制鼠标状态更新
303+
e.Handled = true;
275304
}
276305
}
277306

@@ -306,21 +335,23 @@ private void adm_MouseMove(object sender, MouseEventArgs e)
306335
{
307336
if (isDragging && e.LeftButton == MouseButtonState.Pressed)
308337
{
309-
// 清除旧标记
310-
DragFeedbackLayer.Children.Clear();
338+
// 获取全局鼠标位置
339+
var screenPos = Control.MousePosition;
311340

312-
// 创建新标记
313-
var pos = e.GetPosition(DragFeedbackLayer);
314-
var ellipse = new Ellipse
341+
// 创建或更新全屏标记窗口
342+
if (markerWindow == null)
315343
{
316-
Width = 20,
317-
Height = 20,
318-
Stroke = Brushes.Orange,
319-
StrokeThickness = 2
320-
};
321-
Canvas.SetLeft(ellipse, pos.X - 10);
322-
Canvas.SetTop(ellipse, pos.Y - 10);
323-
DragFeedbackLayer.Children.Add(ellipse);
344+
markerWindow = new MarkerWindow();
345+
markerWindow.Show();
346+
}
347+
348+
// 更新标记位置
349+
markerWindow.UpdatePosition(screenPos.X, screenPos.Y);
350+
}
351+
else if (markerWindow != null)
352+
{
353+
markerWindow.Close();
354+
markerWindow = null;
324355
}
325356
}
326357

Views/MarkerWindow.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
using System.Windows.Media;
4+
using System.Windows.Shapes;
5+
6+
namespace CallRecording.Views
7+
{
8+
public class MarkerWindow : Window
9+
{
10+
private readonly Ellipse marker;
11+
12+
public MarkerWindow()
13+
{
14+
// 设置窗口属性
15+
WindowStyle = WindowStyle.None;
16+
AllowsTransparency = true;
17+
Background = Brushes.Transparent;
18+
Topmost = true;
19+
ShowInTaskbar = false;
20+
ResizeMode = ResizeMode.NoResize;
21+
22+
// 覆盖整个屏幕
23+
Width = SystemParameters.PrimaryScreenWidth;
24+
Height = SystemParameters.PrimaryScreenHeight;
25+
Left = 0;
26+
Top = 0;
27+
28+
// 创建标记
29+
var canvas = new Canvas();
30+
marker = new Ellipse
31+
{
32+
Width = 20,
33+
Height = 20,
34+
Stroke = Brushes.Orange,
35+
StrokeThickness = 2
36+
};
37+
canvas.Children.Add(marker);
38+
Content = canvas;
39+
}
40+
41+
public void UpdatePosition(double x, double y)
42+
{
43+
// 更新标记位置
44+
Canvas.SetLeft(marker, x - 10);
45+
Canvas.SetTop(marker, y - 10);
46+
}
47+
48+
protected override void OnClosed(EventArgs e)
49+
{
50+
base.OnClosed(e);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)