WPF RepeatButton
是一个特殊的按钮,用于在用户长按或连续点击时重复执行特定动作。它通常用于需要重复执行某个操作的场景。
| 常用属性 | 描述 |
|---|---|
| Delay | 用于获取或设置 RepeatButton 在开始重复之前被按下时等待的时间(以毫秒为单位)。 该值必须为非负数。 |
| Interval | 用于获取或设置开始重复后重复之间的时间间隔(以毫秒为单位)。 该值必须为非负数。 |
<Grid>
<StackPanel Margin="0,20,0,0">
<TextBlock Width="350" Margin="0,20,0,20" TextAlignment="Center" Foreground="Red" FontSize="16" Text="注意查看延迟和重复效果需要鼠标按住按钮不放"></TextBlock>
<!--第一个按钮设置点击延迟500毫秒触发,触发后100毫秒执行事件一次-->
<RepeatButton Width="100" Delay="500" Interval="100" Height="30" Background="Blue" Foreground="White" Click="Increase">增加 1 </RepeatButton>
<TextBlock x:Name="myTextBlock" Width="100" Margin="0,10,0,10" TextAlignment="Center" FontSize="16">0</TextBlock>
<!--第二个按钮也设置点击延迟500毫秒触发,触发后100毫秒执行事件一次-->
<RepeatButton Width="100" Delay="500" Interval="100" Height="30" Background="Green" Foreground="White" Click="Decrease">减少 1</RepeatButton>
<TextBlock x:Name="myViewTextBlock" Width="350" Margin="0,20,0,20" TextAlignment="Center" Foreground="Orange" FontSize="16" Text=""></TextBlock>
</StackPanel>
</Grid>
参考:https://blog.csdn.net/u010784529/article/details/135828541

浙公网安备 33010602011771号