0

Hello community I have the following xaml.

<UserControl x:Class="Sample.SampleController"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="410" d:DesignWidth="324">
    <UserControl.Resources>
        <Style x:Key="buttonON" TargetType="RepeatButton">

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RepeatButton">
                        <Grid Width="80"
                              Height="80">
                            <Image Source="/Sample;component/icons/altitude_up_yellow.png"  
                                   Stretch="Fill" RenderOptions.BitmapScalingMode="Fant"/>
                            <ContentPresenter HorizontalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid Name="DriveGrid" Background="#C9000000" Width="324" Height="410">

        <RepeatButton HorizontalAlignment="Left" x:Name="button1" VerticalAlignment="Top"  IsEnabled="True" Style="{StaticResource buttonON}"  Margin="232,297,0,0" Delay="100" Interval="200" Width="80" Height="80"/>


    </Grid>
</UserControl>

And the following Code Behind

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Controls.Primitives;



namespace Sample {

    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class SampleController : UserControl {

        public SampleController() {
            InitializeComponent();
            button1.Click += new RoutedEventHandler(UpBtn_Click);

        }

         void UpBtn_Click(object sender, RoutedEventArgs e) {
            Console.WriteLine("Click");
        }


    }
}

My question, why doesn't the repeat button fire off continously when I press and hold?

Thank you for your help.

DoubleDunk
  • 909
  • 3
  • 11
  • 29
  • Have you tried setting `Background="Transparent"` on root grid in the template of the button? – XAMeLi Jul 30 '13 at 20:57
  • 1
    @DoubleDunk, Does it fire only once or never? Don't know if this is copy/paste error or you mixed controls but your class name is `SampleController` but it has constructor for `CmdController`. – dkozl Jul 30 '13 at 21:19
  • I am sorry for the copy/paste error, you are absolutely right. To answer your questions, when I press and hold it only fires off the click event once. – DoubleDunk Jul 30 '13 at 21:29
  • @Stewbob Actually in my case it only fires off once when I click and hold, I do not have to release it button. – DoubleDunk Jul 30 '13 at 21:31
  • @DoubleDunk, I cannot reproduce it here as it keeps triggering `Click` event. I only found [this](http://social.msdn.microsoft.com/Forums/silverlight/en-US/5d9dc124-b9d3-48e8-a6f9-c1f9d9a49c20/repeatbutton-fires-event-only-once). Maybe it will give you an idea for a workaround – dkozl Jul 30 '13 at 21:58
  • Thank you for your comments community, as dkozl suggested it does work when I take it out of my project and make it a standalone wpf application. I have to inspect this further, but for the time being I used a timer/preview_onclick combination to mimic the effect. I would gladly post some source code if anyone is interested. @dkozl If you would post your comment as an answer, I would gladly accept it. Thank you everyone. – DoubleDunk Aug 15 '13 at 18:29
  • @DoubleDunk, I've posted my comment as an answer. Post your workaround as another answer – dkozl Aug 15 '13 at 19:11

1 Answers1

1

To sum up comments. Even though I am not able to reproduce the problem stated in the question, as the code above works fine for me, I have found very similar issue in RepeatButton fires event only once! article. There is no definite answer what's causing the issue but it may give some clues to what to try

dkozl
  • 32,814
  • 8
  • 87
  • 89