locked
Show a dialog inside touchup event RRS feed

  • Question

  • Hi, I  display a dialog when touching the button.

    the problem is the touch event wouldn't  work when I first touch the buttons inside the dialog.

    but if I use mouse to click my buttons, it works fine!

    Here is my project https://github.com/qucc/ShowDialogInTouchUpEvent . the exe is inside the debug/bin directory.

    Wednesday, April 29, 2015 10:08 AM

Answers

  • Hi quleo,

    The touch events which wasn't handle is translated into a mouse event.
    Probably, this translation process will be incomplete caused by show dialog.

    private void Button_TouchUp(object sender, TouchEventArgs e)
    {
        Action act = () =>
        {
            var dialog = new MyDialog();
            var result = dialog.ShowDialog();
            lable.Text = result.Value ? "1" : "2";
        };
        this.Dispatcher.BeginInvoke(act, null);
    }


    個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)

    • Marked as answer by quleo Tuesday, May 5, 2015 5:10 AM
    Thursday, April 30, 2015 9:37 AM

All replies

  • Hi quleo,

    The touch events which wasn't handle is translated into a mouse event.
    Probably, this translation process will be incomplete caused by show dialog.

    private void Button_TouchUp(object sender, TouchEventArgs e)
    {
        Action act = () =>
        {
            var dialog = new MyDialog();
            var result = dialog.ShowDialog();
            lable.Text = result.Value ? "1" : "2";
        };
        this.Dispatcher.BeginInvoke(act, null);
    }


    個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)

    • Marked as answer by quleo Tuesday, May 5, 2015 5:10 AM
    Thursday, April 30, 2015 9:37 AM
  • Hi quleo,

    In my experience, when you touch the screen, WPF generates touch events, such as TouchDown, TouchMove, and TouchUp. These are all routed events, which means that first the PreviewTouchDown event is fired on the root of the visual tree, then the next element down the hierarchy, then the next, all the way down the source element that the touch event occured over, as long as the event is not handled along the way.

    I have edited your TouchUp event, you could refer to it.

    private void Button_TouchUp(object sender, TouchEventArgs e)
            {
                FrameworkElement button = sender as FrameworkElement;
                if (button == null)
                    return;
         
                TouchPoint tp = e.GetTouchPoint(button);
                Rect bounds = new Rect(new Point(0, 0), button.RenderSize);
                if (bounds.Contains(tp.Position))
                {
                    var dialog = new MyDialog();
                    var result = dialog.ShowDialog();
                    lable.Text = result.Value ? "1" : "2";
                }
                    
                button.ReleaseTouchCapture(e.TouchDevice);
         
                e.Handled = true;
            }

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 5, 2015 3:33 AM
  • Thanks, gekka. I tried your way, it works. 

    Tuesday, May 5, 2015 4:32 AM