20230201_145_upperpc/InSituLaboratory/Views/Pages/CavityOperationView.xaml.cs
2024-03-15 10:27:50 +08:00

55 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace InSituLaboratory.Views.Pages
{
/// <summary>
/// CavityOperationView.xaml 的交互逻辑
/// </summary>
public partial class CavityOperationView : UserControl
{
public CavityOperationView()
{
InitializeComponent();
}
/// <summary>
/// 支持鼠标滚轮上下滚动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
ScrollViewer viewer = sv; //sv 为Scrollview的名字在Xaml文件中定义。
if (viewer == null) return;
double num = Math.Abs((int)(e.Delta / 2));
double offset = 0.0;
if (e.Delta > 0)
{
offset = Math.Max((double)0.0, (double)(viewer.VerticalOffset - num));//viewer.VerticalOffset获取包含滚动内容的垂直偏移量的值。
}
else
{
offset = Math.Min(viewer.ScrollableHeight, viewer.VerticalOffset + num);
}
if (offset != viewer.VerticalOffset)
{
viewer.ScrollToVerticalOffset(offset);//将 ScrollViewer 内的内容滚动到指定的垂直偏移量位置。
e.Handled = true;
}
}
}
}