Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望添加对触屏的一点优化 #47

Open
CheYHinSpark opened this issue Aug 18, 2020 · 1 comment · Fixed by #48
Open

希望添加对触屏的一点优化 #47

CheYHinSpark opened this issue Aug 18, 2020 · 1 comment · Fixed by #48

Comments

@CheYHinSpark
Copy link
Contributor

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);
    }

本人纯小白,不知道有没有什么更好的实现方法……也不知道大佬们还有没有关注这个……

@chenguanzhou
Copy link
Owner

感谢关注。你有空的话,可以把代码拉下来,提交一个pull request

@chenguanzhou chenguanzhou linked a pull request Aug 20, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants