2013-07-30 68 views
0

Hello社區我有以下xaml。重複按鈕wpf未觸發點擊事件

<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> 

以下代碼

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


    } 
} 

我的問題背後,爲什麼不重複扣火過汽車無當我按住?

謝謝你的幫助。

+0

您是否嘗試過在按鈕模板中的根網格上設置'Background =「Transparent」'? – XAMeLi

+1

@ DoubleDunk,它只會觸發一次還是永遠不會觸發?不知道這是複製/粘貼錯誤還是混合控件,但是你的類名稱是'SampleController',但它具有'CmdController'的構造函數。 – dkozl

+0

對於複製/粘貼錯誤,我很抱歉,你是對的。要回答您的問題,當我按住它時,只會觸發點擊事件一次。 – DoubleDunk

回答

1

總結評論。儘管我無法重現問題中提到的問題,但由於上述代碼對我來說工作正常,因此我在RepeatButton fires event only once!文章中發現了非常類似的問題。沒有確切的答案是什麼導致了這個問題,但它可能會提供一些線索,以嘗試什麼