我尝试在视图中呈现可点击项目的列表。我想添加一个带有图像和白色边框的按钮(第一个)。我发现 StackLayout/ViewCell 中的按钮无法渲染边框。
<?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:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
x:Class="*.PlacesPage"
Title="TEST">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0" />
</ContentPage.Padding>
<ContentPage.Content>
<Grid>
<ListView x:Name="lvPlaces" ItemsSource="{Binding Places}" SeparatorColor="Gray" SeparatorVisibility="Default" RowHeight="120" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal">
<Button HorizontalOptions="Center" VerticalOptions="Center" BorderWidth="3" BorderColor="White" Text="IMG"></Button>
<Button Text="{Binding Name}" BorderWidth="0" FontSize="20" BackgroundColor="Transparent" Clicked="OnButtonClickedPlace"></Button>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage.Content>
我正在使用 Xamarin.Forms 2.3,并且我还尝试创建一个按钮,没有边框半径,背景颜色设置为白色,边框颜色和宽度,以上答案都不适合我。
实际上我仍然必须将 BorderRadius 设置为 1(我的宽度是 2),并添加另一个我无法理解的解决方法:
在我的 Android 项目中,我为 Button 添加了一个自定义渲染器,其中没有任何内容。绝对没有。
因此,当您使用默认渲染器时,以及当您使用从默认渲染器继承但其中没有任何代码行的自定义渲染器时,Xamarin 表单的行为在 Android 上是不同的。
我的渲染器:
[assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(GenericButtonRenderer))]
namespace Express.CustomRenderers
{
public class GenericButtonRenderer : Xamarin.Forms.Platform.Android.ButtonRenderer
{
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)