不使用本机渲染器自定义ListView
有没有办法在没有自定义渲染器的情况下自定义Xamarin.Forms列表视图(或单元格) 我发现的每个结果都使用本机渲染器进行解释,但这不是我想要的 我只想从我的共享项目PCL中定制我的ListView或ListView的单元格,以保持Xamarin.Forms的力量,并在应用程序之间共享每个UI代码 编辑1:不使用本机渲染器自定义ListView,listview,xamarin.forms,Listview,Xamarin.forms,有没有办法在没有自定义渲染器的情况下自定义Xamarin.Forms列表视图(或单元格) 我发现的每个结果都使用本机渲染器进行解释,但这不是我想要的 我只想从我的共享项目PCL中定制我的ListView或ListView的单元格,以保持Xamarin.Forms的力量,并在应用程序之间共享每个UI代码 编辑1: public class TappticCell : ViewCell { #region BindableProperty Fields public static
public class TappticCell : ViewCell
{
#region BindableProperty Fields
public static readonly BindableProperty NameProperty =
BindableProperty.Create("Name", typeof(string), typeof(string), "");
public static readonly BindableProperty NameColorProperty =
BindableProperty.Create("NameColor", typeof(Color), typeof(Color), Color.Transparent);
#endregion
#region BindableProperty Properties
public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public Color NameColor
{
get { return (Color)GetValue(NameColorProperty); }
set { SetValue(NameColorProperty, value); }
}
#endregion
#region Fields
private readonly Label _nameLabel;
private readonly StackLayout _stackLayout;
#endregion
#region Constructors
public TappticCell()
{
[...]
_nameLabel = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand };
_nameLabel.SetBinding(Label.TextProperty, "Name");
_nameLabel.SetBinding(Label.TextColorProperty, "NameColor");
[...]
}
#endregion
}
我的问题是第二个设置BindablePropertyNameColor不起作用。。。这里是我在XAML中的用法
<cells:TappticCell Image="{Binding Image}"
Name="{Binding Name}"
BackgroundColor="Gray"
NameColor="{Binding Favorite, Converter={StaticResource BooleanToColor}}"
TextSize="30" />
当我将其用于ImageCell时,效果非常好,但不适用于我的自定义单元格
谢谢如果我能清楚地理解您的意思,您需要定制电池的外观。 在这种情况下,我建议使用viewCell来显示UI内容。 下面是如何编写viewCell类
public class EffortMenuCell:ViewCell
{
static int i = 0;
public EffortMenuCell() : base() {
var newLabel2 = new Label () {VerticalOptions = LayoutOptions.CenterAndExpand };
newLabel2.SetBinding (Label.TextProperty, "nameLabel");
var time = new Label ();
time.HorizontalOptions = LayoutOptions.EndAndExpand;
time.VerticalOptions = LayoutOptions.CenterAndExpand;
time.SetBinding (Label.TextProperty, "timespan");
var tempLayout2 = new StackLayout ();
//tempLayout2.BackgroundColor = Color.White;
tempLayout2.Padding = new Thickness(20,0,20,0);
tempLayout2.Spacing = 20;
tempLayout2.Orientation = StackOrientation.Horizontal;
// based on index Different Row appearance ,
if (i == 0) {
tempLayout2.BackgroundColor = Color.FromHex ("e0e0e0");
newLabel2.TextColor = Color.FromHex ("a4a4a4");
time.TextColor = Color.FromHex ("01bcbc");
this.IsEnabled = false;
i++;
} else {
if (i <= 4) {
tempLayout2.BackgroundColor = Color.White;
newLabel2.TextColor = Color.Black;
time.TextColor = Color.FromHex ("007fbf");
i++;
}
if (i == 5) {
i = 0;
}
}
tempLayout2.Children.Add (newLabel2);
tempLayout2.Children.Add (time);
this.View = tempLayout2;
}
}
public类EffortMenuCell:ViewCell
{
静态int i=0;
public EffortMenuCell():base(){
var newLabel2=newlabel(){VerticalOptions=LayoutOptions.CenterAndExpand};
newLabel2.SetBinding(Label.TextProperty,“nameLabel”);
var-time=新标签();
time.horizontalpoptions=LayoutOptions.EndAndExpand;
time.VerticalOptions=LayoutOptions.CenterAndExpand;
time.SetBinding(Label.TextProperty,“timespan”);
var tempLayout2=新的StackLayout();
//tempLayout2.BackgroundColor=颜色.白色;
模板布局2.填充=新厚度(20,0,20,0);
模板布局2.间距=20;
tempLayout2.Orientation=StackOrientation.Horizontal;
//基于索引不同的行外观,
如果(i==0){
tempLayout2.BackgroundColor=Color.FromHex(“e0”);
newLabel2.TextColor=Color.FromHex(“a4a4a4”);
time.TextColor=Color.FromHex(“01bcbc”);
this.IsEnabled=false;
i++;
}否则{
如果(i可能是你的选择
特效允许自定义每个平台上的本机控件,通常用于小的样式更改。本文介绍特效,概述特效和自定义渲染器之间的边界,并描述PlatformEffect类
如果你想完全控制listview,还需要一个渲染器。你想用XAML还是代码?看看listview。ItemTemplate
是的,这正是我想做的!谢谢!我想我必须做一个自定义渲染器才能在平台之间获得统一的UI!我希望你能接受这个答案,因为这对你很有帮助u.是:)但我还有一个问题!我的标签绑定有问题。我用代码编辑了我的问题:)为什么创建了可绑定属性?这不是必需的,因为你不使用自定义渲染器。另外,标签已经有,TextProperty;FontProperty;TextColorProperty,你可以轻松绑定它们。请遵循下面的链接,因为如果我不这样做的话是的,我不能绑定在xaml页面中传递的不同值