[英]Xamarin.Forms PCL/SAP Custom renders with paintcode 3 support
[英]xamarin PCL forms shared custom controls
自定義渲染器是特定於平台的。 它們的目的是將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>
您需要針對不同平台的自定義渲染器,以便您可以訪問平台提供的本機窗口小部件。
但是,如果您想自己繪制所有自定義控件,可以使用skiasharp跨平台繪圖庫來實現結果。 有關更多詳細信息,請參閱此博客文章: 使用SkiaSharp的跨平台2D圖形
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.