locked
Bug with the button control (excessive event processing delay)

    Question

  • If you use the button control and bind (from code-behind) an event handler to the Tapped event, sometime (1 every 3 click in my case) the event is not handled, resulting in unresponsive UI.

    Using the Click event solved the problem (I believe click event are chained) since the button was used to increase/decrease a product quantity it was imperative it responded to multiple quick tap/click... Even when only using debug.writeline with a counter the behavior is happening.

    Friday, October 10, 2014 11:38 PM

Answers

  • Hi ClementM,

    I cannot repro your scenario. I build a project to handle tap event and click event. I add Debug.Writeln method into tap event handler. In my test, the response of the app is smooth and show the result as expect. My code looks like the following.

    In XAML.

    <StackPanel>
    
                <Button Content="hello"   Tapped="Button_Tapped" Click="Button_Click_1"></Button>
    
                <ListBox x:Name="listbox1" Height="500"></ListBox>
    
            </StackPanel>
    

    In XAML.cs

    private void Button_Tapped(object sender, TappedRoutedEventArgs e)
    
            {
    
                listbox1.Items.Add(DateTime.Now.ToString());
    
                Debug.WriteLine(ran.Next(0, 101));
    
            }
    
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
    
            {
    
                listbox1.Items.Add("click" + DateTime.Now.ToString());
    
            }
    

    Could you please send me a repro project? I will look into it. Use your OneDrive and share a link here.

    In your scenario, I would recommend you use RepeatButton control. This control can call click event repeatedly until you release the click. Code may look like.

    In XAML.

    <TextBox x:Name="txt"></TextBox>
    
                <RepeatButton Content="click me" Click="RepeatButton_Click"></RepeatButton>
    

    In XAML.cs

    private void RepeatButton_Click(object sender, RoutedEventArgs e)
    
            {
    
                int count = 0;
    
                if (!Int32.TryParse(txt.Text,out count))
    
                {
    
                    count = 0;
    
                }
    
                txt.Text = Convert.ToString(++count);
    
            }
    

    If you still have questions, please post more information about your scenario.

    Regards,


    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.

    Monday, October 13, 2014 7:59 AM
    Moderator

All replies

  • Hi ClementM,

    I cannot repro your scenario. I build a project to handle tap event and click event. I add Debug.Writeln method into tap event handler. In my test, the response of the app is smooth and show the result as expect. My code looks like the following.

    In XAML.

    <StackPanel>
    
                <Button Content="hello"   Tapped="Button_Tapped" Click="Button_Click_1"></Button>
    
                <ListBox x:Name="listbox1" Height="500"></ListBox>
    
            </StackPanel>
    

    In XAML.cs

    private void Button_Tapped(object sender, TappedRoutedEventArgs e)
    
            {
    
                listbox1.Items.Add(DateTime.Now.ToString());
    
                Debug.WriteLine(ran.Next(0, 101));
    
            }
    
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
    
            {
    
                listbox1.Items.Add("click" + DateTime.Now.ToString());
    
            }
    

    Could you please send me a repro project? I will look into it. Use your OneDrive and share a link here.

    In your scenario, I would recommend you use RepeatButton control. This control can call click event repeatedly until you release the click. Code may look like.

    In XAML.

    <TextBox x:Name="txt"></TextBox>
    
                <RepeatButton Content="click me" Click="RepeatButton_Click"></RepeatButton>
    

    In XAML.cs

    private void RepeatButton_Click(object sender, RoutedEventArgs e)
    
            {
    
                int count = 0;
    
                if (!Int32.TryParse(txt.Text,out count))
    
                {
    
                    count = 0;
    
                }
    
                txt.Text = Convert.ToString(++count);
    
            }
    

    If you still have questions, please post more information about your scenario.

    Regards,


    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.

    Monday, October 13, 2014 7:59 AM
    Moderator
  • Do it in VB and bind the handler using AddHandler or via XAML

    Thursday, October 23, 2014 2:08 AM
  • The Click event work just fine... And it's only with the button control (maybe using multiple dispatchtimer created the bug)
    Thursday, October 23, 2014 2:10 AM