this used to work on Xamarin.Forms but on Maui seems to be not working. I have downloaded your sample and slightly modified as attached. If I call LoadData from ViewModel Constructor it works fine but if i need to call from OnAppearing, Bindings are not work. Please see the attached sample.
Hi Emil,
Regarding “SfKanban binding not working calling in OnAppearing, only works through constructor”
Thank you for sharing the modified sample.
We have reviewed the sample and made a few necessary
adjustments to ensure the binding works as expected. Specifically, we
initialized the Columns and Cards collections in the ViewModel constructor, and
added the data population logic in LoadData method, which is then called in the
OnAppearing override. With these changes, the bindings work correctly.
C#:
|
public ViewModel() { Columns = new KanbanColumnCollection(); Cards = new ObservableCollection<KanbanModel>(); } |
We have updated the sample accordingly and attached it
for your reference. Please take a moment to review it and let us know if you
have any further questions or need help with a specific scenario.
Thank you for your continued support and patience.
Regards,
Kerubananthan G
I have already figured out this myself but this needs to be stated somewhere on xamarin.forms to maui upgrade documentation if it is intended, otherwise it is regression. it costs me half a day yesterday to figure out why SfKanban upgrade from XF to Maui not working. because this used to work on XF without using constructor initilization. thank you for your help.
Hi Emil,
Thank you for sharing your experience, and we understand
the frustration this may have caused during your upgrade from Xamarin.Forms to
.NET MAUI.
Initialization of Columns property before setting BindingContext:
To ensure the SfKanban control functions correctly in .NET MAUI, it's important to initialize the Columns property in the view model constructor before assigning the BindingContext in the view. For example:
C#:
|
public class ViewModel { public ObservableCollection<KanbanModel> Cards { get; set; } public KanbanColumnCollection Columns { get; set; } public ViewModel() { Columns = new KanbanColumnCollection(); Cards = new ObservableCollection<KanbanModel>(); }
public void LoadData() { Columns.Add(new KanbanColumn() { Categories = new List<object> { "Open" }, Title = "Open", });
Cards.Add(new KanbanModel() { ID = 1, Title = "iOS - 1002", ImageURL = "People_Circle1.png", Category = "Open", Description = "Analyze customer requirements", IndicatorFill = Colors.Red, Tags = new List<string> { "Incident", "Customer" } }); } } |
When the property is initialized this way, INotifyPropertyChanged is not required for the Columns property, as the binding system can resolve the initial value at the time the BindingContext is set.
Initialization of Columns property after
BindingContext:
However, if the Columns property is assigned or updated after the BindingContext
has already been set, then INotifyPropertyChanged is required. This is because
the view needs to be notified that the entire collection reference has changed.
C#:
|
public class ViewModel : INotifyPropertyChanged { public KanbanColumnCollection _columns; public ObservableCollection<KanbanModel> _cards;
public ObservableCollection<KanbanModel> Cards { get { return _cards; } set { _cards = value; this.OnPropertyChanged(nameof(Cards)); } }
public KanbanColumnCollection Columns { get => _columns; set { if (_columns != value) { _columns = value; OnPropertyChanged(nameof(Columns)); } } }
public ViewModel() { }
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }
public void LoadData() { Columns = new KanbanColumnCollection(); Columns.Add(new KanbanColumn() { Categories = new List<object> { "Open" }, Title = "Open", });
Cards = new ObservableCollection<KanbanModel>(); Cards.Add(new KanbanModel() { ID = 1, Title = "iOS - 1002", ImageURL = "People_Circle1.png", Category = "Open", Description = "Analyze customer requirements", IndicatorFill = Colors.Red, Tags = new List<string> { "Incident", "Customer" } }); } } |
Thank you for bringing this to our attention. We will include this behavioral difference from Xamarin.Forms in the migration user guide.
Regards,
Kerubananthan G