I have a general Xamarin.Forms project and the problem exists only on Android. My problem is that I have a list, and when I click a button in my custom cell, it changes color (from blue to green). Then I press another button that opens another page, and when I close this page, the item is removed from the list. But now the element below the shot has a green button, not a blue one. Here is an example:
- The first image. When displaying a ListView with a custom cell inside containing information and two buttons, note that they are blue.
- The second image. Showing that I pressed the first button, and now it has turned green.
- Thrid image - Displays the page that is pressed when I press the second button.
- The fourth image. Now I clicked the “Bekræft" button on the image before, and the message was sent to the list page to remove the RouteElement from the list (and so it is). But now the first button is green, even if it has not been pressed.
RouteElement Model.
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);
Then I call this function of the MessagingCenter to delete from another page in the navigation.
MessagingCenter.Subscribe<RouteElement>(this, "Refresh",(sender) => { RouteElement r = (RouteElement)sender; rOC.Remove(r); }
And now the second RouteElement button is green, although it should be blue. Any help is much appreciated!
This "error" only occurs on Android with the latest Xamarin.Forms package
<package id="Xamarin.Forms" version="2.3.3.193" targetFramework="monoandroid70" />
It works great on Android with this Xamarin.Forms package.
<package id="Xamarin.Forms" version="2.2.0.31" targetFramework="monoandroid70" />