Bryan
Bryan

Reputation: 63

How to add android attributes like android:id on Xamarin Forms(XAML)?

I've already tried setting android attributes like contentdescription by creating a custom element and setting the attribute on the renderer using the control.

Control.ContentDescription = ((MyEntry)e.NewElement).ContentDescription;

Is there a way to do it on the XAML rather than custom renderer? Another, how can I set the android:id attribute? I've tried it change it on custom render but I think it's not working.

Sidenote: I'm using a RealWear device which can generats a script which has the UI elements of the page. The UI elements will contain the id attribute if it exists.

Upvotes: 0

Views: 930

Answers (1)

Markus Michel
Markus Michel

Reputation: 2299

Hello and welcome to StackOverflow. you can't add Android descriptions to xamarin forms elements.

Xamarin forms abstracts the ui to a non-native format (xaml) and converts the abstract definition of an element to a native one. However this happens "under the hood" and therefore you don't have direct access to that from xamarin.forms.

What you could do is, if you really need an element with a set id, you can either find a way to hack in your id using a custom renderer or you create and embed native elements. For the latter please see the following microsoft article, which is a bit too much to include within this answer: https://msdn.microsoft.com/en-us/magazine/mt790186.aspx

Upvotes: 1

Related Questions