Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin forms use native platform specific controls.

$
0
0

In my Xamarin forms App I want to show platform specific controls Spinner in Android and Segmented Control in iOS. I have written the custom view(Derived from Xamarin Forms View) and platform specific renderers(ViewRenderer). For Android in "OnElementChanged" method I am setting Spinner view. But it ends in following exception:

Java.Lang.RuntimeException: Binary XML file line #19: You must supply a layout_height attribute.

I tried to set LayoutParams but it's not working.

Code:
XAML:
StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="Center" BackgroundColor="Aqua"
local:CustomGradeView HorizontalOptions="Fill" VerticalOptions="Fill"
StackLayout

public class CustomGradeView : View{}

public class CustomGradeRenderer : ViewRenderer
    {
        Spinner spinnerView;

        protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged (e);

            // SetNativeControl (new TextView(Context){Text="Test for renderer"}); Working fine, no issues.

            spinnerView = new Spinner (Context);
            spinnerView.LayoutParameters = new LayoutParams (100, 100);
            ArrayAdapter<string> spinnerAdapter =
                new ArrayAdapter<string> (Context, Resource.Layout.support_simple_spinner_dropdown_item, grades);
            spinnerView.Adapter = spinnerAdapter;
            SetNativeControl (spinnerView); // Exception
        }
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>