Hello,
Welcome to our Microsoft Q&A platform!
I find use Dependence Service cannot get the TextView
, So I achive it in the Custom Renderer. we should create a custom Label
. Create a method called GetAccessibilityForLabel
,
public class MyLabel:Label
{
public event EventHandler GetAccessibility;
public void GetAccessibilityForLabel() {
if (GetAccessibility != null)
{
GetAccessibility(this, EventArgs.Empty);
}
}
}
then we can call it in the button click event,
private void Button_Clicked(object sender, EventArgs e)
{
myLabel.GetAccessibilityForLabel();
}
Then we can achieve this get Accessibility in the custom renderer with textView.SendAccessibilityEvent(EventTypes.ViewHoverEnter);
.
namespace App150.Droid
{
class MyLabelRenderer : LabelRenderer
{
public MyLabelRenderer(Context context) : base(context)
{
}
TextView textView;
MyLabel myLabel;
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
textView = Control as TextView;
myLabel = e.NewElement as MyLabel;
myLabel.GetAccessibility += OnAccessibilityRequested;
}
if (e.OldElement != null)
{
myLabel.GetAccessibility -= OnAccessibilityRequested;
}
}
private void OnAccessibilityRequested(object sender, EventArgs e)
{
Device.BeginInvokeOnMainThread(() => {
textView.SendAccessibilityEvent(EventTypes.ViewHoverEnter);
});
}
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.