工作中遇到这样的一个需求,模仿微信发生语音功能,需要实现按钮按下开始录音,按钮释放录音结束,

Xamarin.Forms中Button没有这样的事件,那么我们如何实现对Button按下,释放两个事件的监听呢?

当然这里我们再次用到了CustomRenderer,一旦遇到Xamrin.Forms无法实现的某些功能,我们就可以

通过CustomRenderer来处理。

首先:我们自定义一个VoiceRecordButton继承于Button

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Diagnostics;
 4 using System.Text;
 5 using System.Windows.Input;
 6 using Xamarin.Forms;
 7 
 8 namespace XFPractice.CustomView
 9 {
10     public class VoiceRecordButton: Button
11     {
12 
13         public ICommand StartCommand { get; set; }
14         public ICommand EndCommand { get; set; }
15 
16         public VoiceRecordButton()
17         {
18             StartCommand = new Command(()=> {
19                 Debug.WriteLine(" StartCommand =========== ");
20             });
21 
22             EndCommand = new Command(() => {
23                 Debug.WriteLine(" EndCommand =========== ");
24             });
25         }
26 
27     }
28 }
View Code

相关文章:

  • 2021-11-27
  • 2021-06-30
  • 2021-12-28
  • 2021-10-19
  • 2022-01-06
  • 2020-06-12
猜你喜欢
  • 2020-05-04
  • 2021-11-27
  • 2021-12-19
  • 2021-11-17
  • 2021-07-07
  • 2021-05-22
  • 2021-09-29
  • 2021-12-04
相关资源
相似解决方案