我有一個共享的Xamarin.Forms項目,這個問題只存在於Android上。我的問題是,我有一個列表視圖,當我點擊我的自定義單元中的按鈕時,它會更改顏色(從藍色到綠色)。然後,我點擊另一個按鈕,打開另一個頁面,當我關閉該頁面時,該項目將從列表視圖中刪除。但是現在,刪除的項目下方有一個綠色按鈕,而不是藍色。 下面是一個例子:Xamarin在Listview按鈕中顯示CustomCell背景綁定不起作用?
- 第一圖像 - 顯示與內部包含信息和2個按鈕一個customcell ListView中,注意到它們是藍色的。
- 第二圖像 - 即顯示我已按下第一按鈕,並且它現在已經變成了綠色。
- THRID圖像 - 顯示當我按下第二按鈕被按下的頁面。
- 第四圖像 - 現在我以前已經點擊在圖像上的「Bekræft」按鈕,該消息已被髮送到ListView頁面以除去RouteElement從列表(以及它)。但現在第一個按鈕是綠色的,即使它沒有被按下。
的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的按鈕是綠色的,儘管它應該是藍色的。任何幫助深表感謝!
這個「錯誤」只發生在Android上Xamarin.Forms的最新包裝
<package id="Xamarin.Forms" version="2.3.3.193" targetFramework="monoandroid70" />
它正常工作在Android上這個包Xamarin.Forms的
<package id="Xamarin.Forms" version="2.2.0.31" targetFramework="monoandroid70" />
你能分享完整的項目,以便快速重現問題嗎? –
@YuriS - 不能這樣做。 –
測試項目可能很有用。 – Scinfu