Xamarin forms - 创建复杂的自定义控件(创建多个交通标志)
Xamarin forms - Create complex custom control (create multiple traffic signs)
我在 Android 项目中有以下屏幕:
如何在 Xamarin 表单中创建这样的控件? (真的不想原生实现)
您可以使用 Frame 并设置 Padding 和 CornerRadius 。
例如
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Frame BackgroundColor="Red" CornerRadius="10" WidthRequest="100" HeightRequest="50" Padding="5">
<Frame BackgroundColor="White" CornerRadius="8" WidthRequest="90" HeightRequest="40" Padding="5" >
<Frame BackgroundColor="Red" CornerRadius="8" WidthRequest="80" HeightRequest="30" Padding="0">
<Label Text="11111" TextColor="White" FontSize="20" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</Frame>
</Frame>
</Frame>
</StackLayout>
您可以将上述代码放在自定义视图中,并在后面的代码中绑定颜色和文本。
我在 Android 项目中有以下屏幕:
如何在 Xamarin 表单中创建这样的控件? (真的不想原生实现)
您可以使用 Frame 并设置 Padding 和 CornerRadius 。
例如
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Frame BackgroundColor="Red" CornerRadius="10" WidthRequest="100" HeightRequest="50" Padding="5">
<Frame BackgroundColor="White" CornerRadius="8" WidthRequest="90" HeightRequest="40" Padding="5" >
<Frame BackgroundColor="Red" CornerRadius="8" WidthRequest="80" HeightRequest="30" Padding="0">
<Label Text="11111" TextColor="White" FontSize="20" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</Frame>
</Frame>
</Frame>
</StackLayout>
您可以将上述代码放在自定义视图中,并在后面的代码中绑定颜色和文本。