Open CheYHinSpark opened 4 years ago
WPF是支持触屏的。我自己用的电脑是触屏的,在用手指触摸移动的时候,我不希望出现选择文本的那种效果,而是翻页效果。当然在用鼠标时还是像原来一样。我自己的方法是在MainWindow.xaml.cs里面加了以下内容:
private Point touchStartPoint; private Point touchEndPoint; //右边的部分 private void MvvmCWBrowser_PreviewTouchDown(object sender, System.Windows.Input.TouchEventArgs e) { string src = $"onmousedown=new Function(\"return false\")"; mvvmCWBrowser.GetMainFrame().ExecuteJavaScriptAsync(src); touchStartPoint = e.GetTouchPoint(mvvmCWBrowser).Position; } private void MvvmCWBrowser_PreviewTouchMove(object sender, System.Windows.Input.TouchEventArgs e) { touchEndPoint = e.GetTouchPoint(mvvmCWBrowser).Position; string src = $"scrollBy({-touchEndPoint.X+touchStartPoint.X}, {-touchEndPoint.Y + touchStartPoint.Y})"; mvvmCWBrowser.GetMainFrame().ExecuteJavaScriptAsync(src); touchStartPoint = touchEndPoint; } //左边的部分 private void MvvmTextEditor_PreviewTouchDown(object sender, System.Windows.Input.TouchEventArgs e) { touchStartPoint = e.GetTouchPoint(mvvmTextEditor).Position; mvvmTextEditor.IsTouched = true; } private void MvvmTextEditor_PreviewTouchMove(object sender, System.Windows.Input.TouchEventArgs e) { touchEndPoint = e.GetTouchPoint(mvvmTextEditor).Position; mvvmTextEditor.ScrollToVerticalOffset(mvvmTextEditor.VerticalOffset + (touchStartPoint.Y - touchEndPoint.Y)); touchStartPoint = touchEndPoint; }
然后在MvvmTextEditor.cs里加了
public bool IsTouched = false; protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { if (!IsTouched) { base.OnPreviewMouseDown(e); } else { e.Handled = true; } } protected override void OnPreviewMouseUp(MouseButtonEventArgs e) { if (!IsTouched) { base.OnPreviewMouseUp(e); } else { e.Handled = true; } IsTouched = false; }
最后在MvvmChromiumWebBrowser中加
protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); string src = $"onmousedown=new Function(\"return true\")"; this.GetMainFrame().ExecuteJavaScriptAsync(src); }
本人纯小白,不知道有没有什么更好的实现方法……也不知道大佬们还有没有关注这个……
感谢关注。你有空的话,可以把代码拉下来,提交一个pull request
WPF是支持触屏的。我自己用的电脑是触屏的,在用手指触摸移动的时候,我不希望出现选择文本的那种效果,而是翻页效果。当然在用鼠标时还是像原来一样。我自己的方法是在MainWindow.xaml.cs里面加了以下内容:
然后在MvvmTextEditor.cs里加了
最后在MvvmChromiumWebBrowser中加
本人纯小白,不知道有没有什么更好的实现方法……也不知道大佬们还有没有关注这个……