Note: I am assuming you are using a .NetStd library project and not a Shared Code project as the "container
" of your XAML code and that you are also using the latest version of Xamarin.Forms
android:VisualElement.Elevation="10"
VisualElement.Elevation will become a Forms-based bindable property attached to each control that you are assigning it in when compiled into IL via XAMLC, i.e.
IL_0085: ldsfld [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.PlatformConfiguration.AndroidSpecific.VisualElement::ElevationProperty
So my doubt is, Is it affect the Xaml compilation? If I add the above line of code is it affect my View's Performance?
So it is compiled into IL, the XAML is not embedded in the assembly and of course is present on all platforms that this cross-platform NetStd/PCL assembly is deployed (that is why a platform-based bound property is used). At runtime the property is assigned and yes there is an "overhead" associated to do that:
IL_008a: ldc.r4 10
IL_008f: newobj instance void [netstandard]System.Nullable`1<float32>::.ctor(!0)
IL_0094: box [netstandard]System.Nullable`1<float32>
IL_0099: callvirt instance void [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue([Xamarin.Forms.Core]Xamarin.Forms.BindableProperty,object)
Note: This "overhead" is on all platforms, it would just be on Android that setting the "native" field's Elevation would actually do anything.
Would it be faster and more memory efficient to directly assign the Elevation in a custom Android renderer, yes, but only you can determine if the (small) gain is worth it to your code base.