自定义渲染器是特定于平台的。它们的目的是将 Xamarin.Forms 元素转换为本机控件。
您的用例听起来像一个复合控件。您可以做的是将所有可用的控件包装到可重用组件中。
MyControl.xaml
<?xml version="1.0" encoding="utf-8" ?>
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App3.MyControl">
<Label Text="Hello World" VerticalOptions="Center" HorizontalOptions="Center" />
<BoxView BackgroundColor="Fuchsia"></BoxView>
<!-- add whatever you want -->
</StackLayout>
MyControl.xaml.cs
public partial class MyControl : StackLayout
{
public MyControl()
{
InitializeComponent();
}
}
Page1.xaml
比你可以在你的页面中使用它。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App3;assembly=App3"
x:Class="App3.Page1">
<local:MyControl></local:MyControl>
</ContentPage>