3
votes

I have a question regarding Xamarin forms in my shared library I have a Class called BluetoothPage.cs wich will compiled in Ios,Droid and WinPhone.

Now in Droid shared project I want to access the Listview from the BluetoothPage.cs which is in my shared Library (Portable)

I can make it static but thats not the way we want to go since I want to also bind data specific for every device.

Thats why I want to access it from my .Droid shared project and also from my .IOS shared project.

1

1 Answers

2
votes

Have a look at Custom renderers. What you need to do is write a custom renderer for bluetooth page and then you can access the instance of the forms page from all the platforms.

Shared Code

namespace BluetoothApp
{
    public ListView List {get; set;}

    public class  BluetoothPage : ContentPage
    {
    }

}

iOS

[assembly:ExportRenderer(typeof(BluetoothPage), typeof(BluetoothPageRenderer))]

namespace CustomRenderer.iOS
{
    public class BluetoothPageRenderer : PageRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<ContentPage> e)
        {
            base.OnElementChanged (e);

            var bluetoothPage = (BluetoothPage)e;

            bluetoothPage.List.DoStuff();
        }

    }

}

The Droid and Windows phone renderers will be slightly different but the idea is the same, you can find examples of custom renderers on the docs or here.