Will changing the property value bound to an AutomationID change it?

lbk3lbk3 Member ✭✭

I know that this limitation has existed in the past but I want to ask the question again after the project I am working has recently upgraded to XF4.3. I believe that the automationIDs are set at compile time? My question is that if I bind that AutomationId to a string property which is equal to "Foo", if while the application is running that string value is changed to "Bar", will the AutomationId of the XAML element also change?

Best Answer

Answers

  • lbk3lbk3 Member ✭✭

    @JohnHardman said:

    @lbk3 said:
    I know that this limitation has existed in the past but I want to ask the question again after the project I am working has recently upgraded to XF4.3. I believe that the automationIDs are set at compile time? My question is that if I bind that AutomationId to a string property which is equal to "Foo", if while the application is running that string value is changed to "Bar", will the AutomationId of the XAML element also change?

    Looking in "Merge branch '4.4.0'" at https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/Element.cs

    the following (ridiculous, IMHO) code is still present:

          public string AutomationId
          {
              get { return (string)GetValue(AutomationIdProperty); }
              set
              {
                  if (AutomationId != null)
                      throw new InvalidOperationException($"{nameof(AutomationId)} may only be set one time.");
    
                  SetValue(AutomationIdProperty, value);
              }
          }
    

    So, AutomationId can still only be set once. Attempting to change the value again will still result in the ridiculous exception.

    (I raised a bug against this a long time ago, but it doesn't look like Xamarin will ever remove the restriction on changing an AutomationId).

    I guess, in most circumstances, you shouldn't need to change that AutomationId of an element while debugging. But when you're faced with a scenario that requires it then it's incredibly annoying to see place such a hard line on it.

Sign In or Register to comment.