找到唯一的控制項:AutomationId

做法:

  1. 在button、label…等控制項上加上此屬性AutomationId="btnMakeCall"

  2. 調整Andorid 的MainActivity.cs

  3. 調整iOS的 AppDelegate.cs
-- Android MainActivity.cs
global::Xamarin.Forms.Forms.Init(this, bundle);

Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) => 
{
  if (!string.IsNullOrWhiteSpace(e.View.AutomationId))
   {
    e.NativeView.ContentDescription = e.View.AutomationId;
   }
};
-- iOS AppDelegate.cs

global::Xamarin.Forms.Forms.Init();

Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) => {
    if (null != e.View.AutomationId)
    {
        e.NativeView.AccessibilityIdentifier = e.View.AutomationId;
    }
};

LoadApplication(new App());

Useful Resources

  1. link1

  2. link2

results matching ""

    No results matching ""