locked
Stylus position on canvas RRS feed

  • Question

  • Hello,

    I have a canvas and I want when I touch the screen with the stylus display the coordinate of the position where the stylus touch the canvas. (stylus not mouse)

    Any help would be greatly appreciated!

    Harold

    Friday, August 25, 2017 12:57 AM

Answers

  • You could handle Stylusdown.

    https://msdn.microsoft.com/en-us/library/system.windows.uielement.stylusdown(v=vs.110).aspx

    I think you can then do getposition(canvas).

    https://msdn.microsoft.com/en-us/library/system.windows.input.styluseventargs.getposition(v=vs.110).aspx


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Marked as answer by JH_Levasseur Monday, September 11, 2017 12:56 AM
    Friday, August 25, 2017 8:33 AM

All replies


  • Hi JH_Levasseur,

    >>I have a canvas and I want when I touch the screen with the stylus display the coordinate of the position where the stylus touch the canvas. (stylus not mouse)

    You can get the Position by the StylusEventArgs

     public Readxmlspantotextblock()
            {
                InitializeComponent();
    
                this.StylusDown += Readxmlspantotextblock_StylusDown;
                this.StylusMove += Readxmlspantotextblock_StylusMove;
            }
    
            private void Readxmlspantotextblock_StylusMove(object sender, StylusEventArgs e)
            {
                Point pos = e.GetPosition(this);
            }
    
            private void Readxmlspantotextblock_StylusDown(object sender, StylusDownEventArgs e)
            {
                Point pos = e.GetPosition(this);
            }

    The following link may be helpful for you.

    WPF and multi-touch
    https://www.codeproject.com/Articles/692286/WPF-and-multi-touch

    Best Regards,

    Yohann Lu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, August 25, 2017 8:30 AM
  • You could handle Stylusdown.

    https://msdn.microsoft.com/en-us/library/system.windows.uielement.stylusdown(v=vs.110).aspx

    I think you can then do getposition(canvas).

    https://msdn.microsoft.com/en-us/library/system.windows.input.styluseventargs.getposition(v=vs.110).aspx


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Marked as answer by JH_Levasseur Monday, September 11, 2017 12:56 AM
    Friday, August 25, 2017 8:33 AM
  • That's works fine!

    Thanks  :-)

    Monday, August 28, 2017 12:43 AM

  • Hi JH_Levasseur,

    I am glad to know you solved. It would be appreciated if you could close the thread by marking the helpful solution as an answer. This will help other members to find the solution quickly if they have faced the similar issue.

    You can start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 28, 2017 1:21 AM