Xamarin Forms 访问列表视图
Xamarin Forms Access Listview
我有一个关于 Xamarin 表单的问题
在我的共享库中,我有一个名为 BluetoothPage.cs 的 Class
将在 Ios、Droid 和 WinPhone 中编译。
现在在 Droid 共享项目中,我想从我的共享库(便携式)
中的 BluetoothPage.cs 访问列表视图
我可以让它静态化,但这不是我们想要的方式
因为我还想绑定每个设备的特定数据。
这就是为什么我想从我的 .Droid 共享项目以及我的 .IOS 共享项目访问它的原因。
看看Custom renderers。您需要做的是为蓝牙页面编写一个自定义渲染器,然后您就可以从所有平台访问表单页面的实例。
共享代码
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();
}
}
}
Droid 和 Windows phone 渲染器会略有不同,但想法是一样的,您可以在文档或 here.[=14= 上找到自定义渲染器的示例]
我有一个关于 Xamarin 表单的问题 在我的共享库中,我有一个名为 BluetoothPage.cs 的 Class 将在 Ios、Droid 和 WinPhone 中编译。
现在在 Droid 共享项目中,我想从我的共享库(便携式)
中的 BluetoothPage.cs 访问列表视图我可以让它静态化,但这不是我们想要的方式 因为我还想绑定每个设备的特定数据。
这就是为什么我想从我的 .Droid 共享项目以及我的 .IOS 共享项目访问它的原因。
看看Custom renderers。您需要做的是为蓝牙页面编写一个自定义渲染器,然后您就可以从所有平台访问表单页面的实例。
共享代码
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();
}
}
}
Droid 和 Windows phone 渲染器会略有不同,但想法是一样的,您可以在文档或 here.[=14= 上找到自定义渲染器的示例]