我有一个共享的Xamarin.Forms项目,这个问题只存在于Android上。我的问题是,我有一个listview,当我点击我的customcell中的一个按钮时,它会改变颜色(从蓝色变为绿色)。然后我点击另一个按钮打开另一个页面,当我关闭该页面时,该项目将从列表视图中删除。但现在删除的项目下面的项目有一个绿色按钮,而不是蓝色。 这是一个例子:
RouteElement模型。
public class RouteElement : INotifyPropertyChanged
{
string arrivalBtnColor;
public event PropertyChangedEventHandler PropertyChanged;
public DateTime ArrivalTime { get; set; }
public DateTime DepartureTime { get; set; }
public bool ReadyForService { get; set; }
public bool DeliveredToService { get; set; }
public string ArrivalBtnBColor
{
get { return arrivalBtnColor; }
set
{
if (arrivalBtnColor != value)
{
arrivalBtnColor = value;
OnPropertyChanged("ArrivalBtnBColor");
}
}
}
public RouteElement()
{
this.ArrivalBtnBColor = "Default";
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}
CustomCell
Button ArrivalBtn = new Button
{
Text = "Ankomst",
FontSize = 24,
BorderRadius = 10,
HeightRequest = 75,
TextColor = Color.FromHex("#FFFFFF")
};
ArrivalBtn.SetBinding(Button.BackgroundColorProperty, "ArrivalBtnBColor",BindingMode.Default, new StringToColorConverter(), null);
Label PostalNoLbl = new Label()
{
TextColor = Color.Black,
HorizontalTextAlignment = TextAlignment.Center,
VerticalOptions = LayoutOptions.Start,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
};
PostalNoLbl.SetBinding(Label.TextProperty, "Postcode");
PostalNoLbl.SetBinding(Label.IsVisibleProperty, "Postcode", BindingMode.Default,new StringToBoolConverter(),null);
然后我调用此MessagingCenter功能从导航中的另一个页面中删除。
MessagingCenter.Subscribe<RouteElement>(this, "Refresh",(sender) =>
{
RouteElement r = (RouteElement)sender;
rOC.Remove(r);
}
现在第二个RouteElement的按钮是绿色的,即使它应该是蓝色的。任何帮助深表感谢!
这个“bug”仅在Android上发布,包含最新的Xamarin.Forms包
<package id="Xamarin.Forms" version="2.3.3.193" targetFramework="monoandroid70" />
使用这个Xamarin.Forms包
在Android上运行正常<package id="Xamarin.Forms" version="2.2.0.31" targetFramework="monoandroid70" />
答案 0 :(得分:2)
您是否为ListView定义了ListViewCachingStrategy?您可以尝试:
_listView = new ListView(ListViewCachingStrategy.RecycleElement);
或
_listView = new ListView(ListViewCachingStrategy.RetainElement);
ListView可能错误地重用旧单元格中的颜色(但不重复文本/内容)。
答案 1 :(得分:0)
适用于2.2x但不适用于2.3x 2.3x有很多错误可以在这里阅读
https://forums.xamarin.com/discussion/77854/xamarin-forms-2-3-3-193/p2
由于存在大量漏洞,开发人员建议使用2.2x。我建议一样。