How does ClearBindings() in MvvmCross?
As for testing, I'm just trying to clear the TableViewSource elements in ViewDidLoad() for WeekSelectorView. Here is what I tried, but nothing works.
("this" refers to my current instance of WeekSelectorView)
var source = new WeekSelectorTableSource(TableView, this); TableView.Source = source; var set = this.CreateBindingSet<WeekSelectorView, WeekSelectorViewModel>(); set.Bind(source).To(vm => vm.Options); set.Apply(); //None of these work this.ClearBindings (this); this.ClearBindings (source); this.ClearBindings (TableView.Source); this.ClearBindings (source.ItemsSource); this.ClearBindings ("ItemsSource"); this.ClearBindings ("source.ItemsSource"); this.ClearBindings ("TableView"); this.ClearBindings ("TableView.Source"); this.ClearBindings (TableView); this.ClearBindings ("TableView.Source.ItemsSource"); this.ClearBindings (set); this.ClearBindings ("set"); this.ClearBindings ("Options"); TableView.ReloadData();
Currently, when I download the application, my WeekSelectorView loads a table based on my ViewModel data. I want to clear the binding, so there should be no table.
this.ClearAllBindings();
The above line works, but I don't want to clear ALL the bindings, I just want to clear my TableView ItemsSource.
Edit:
I currently have a WeekSelectorView with its associated .xib. .Xib has a TableView (among other user controls).
My WeekSelectorView sets the source to my own WeekSelectorTableSource class. This tablesource class defines the number of rows / partitions based on the ItemsSource binding. Then it creates some custom .xib cells and inside my GetOrCreateCellsFor
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item) { var weekSelectorCell = WeekSelectorCell.Create(); var set = _WeekSelectorView.CreateBindingSet<WeekSelectorView, WeekSelectorViewModel>();
Now the reason I want ClearBindings() ......
Every time I reload the table, my previous bindings are saved. So, if I associate 4 cells with 3 bindings each, then for the first time my application will have 12 bindings associated with the cells. After reloading the table (still with 4 cells) there will be 24 bindings .... then 36, 48, etc.
Here is a part of Diagnostics ....
2013-07-16 16:26:03.950 FCXiOSv2[569:21e03] MvxBind: Warning: 1259.41 Weak Target is null in MvxWithEventPropertyInfoTargetBinding - skipping set 2013-07-16 16:26:03.951 FCXiOSv2[569:21e03] MvxBind: Diagnostic: 1259.41 Receiving setValue to Week 2013-07-16 16:26:03.952 FCXiOSv2[569:21e03] MvxBind: Warning: 1259.42 Weak Target is null in MvxWithEventPropertyInfoTargetBinding - skipping set 2013-07-16 16:26:03.953 FCXiOSv2[569:21e03] MvxBind: Diagnostic: 1259.42 Receiving setValue to 7/8/13 - 7/14/13 2013-07-16 16:26:03.954 FCXiOSv2[569:21e03] MvxBind: Warning: 1259.42 Weak Target is null in MvxWithEventPropertyInfoTargetBinding - skipping set
I just get a FLOODED message with this message after reloading the table, so I wanted to clear the bindings every time before I got TableView.ReloadData() .
Edit:
After thinking about it and talking to a colleague who works with native Windows connections, I found that there were a lot of things that I did wrong, a short history, I do not need to use ClearBindings(view) .
I had my external view processing the whole binding, since the view was reloaded (the so-called cells in the table), the bindings were still saved because the appearance was not released. So, all my subtitles never processed their own bindings, which was a serious mistake.
To fix this change (to βcorrectβ, as I assume), I had my own inherited cell from MvxTableViewCell and a delay binding was added.
public WeekSelectorCell (IntPtr handle) : base (handle) { this.DelayBind (() => { var set = this.CreateBindingSet<WeekSelectorCell, WeekViewModel>(); set.Bind(DateLabel).For(lbl => lbl.Text).To(vm => vm.DateString); set.Bind(HoursLabel).For (lbl => lbl.Text).To(vm => vm.TotalHours).WithConversion(new HoursDecimalToHoursMinutesConverter(), null); set.Bind(TitleLabel).For(lbl => lbl.Text).To(vm => vm.Title); set.Apply(); }); }
I tried this before, but tried to create a set between <WeekSelectorCell, WeekSelectorViewModel> and tried to access (vm => vm.Options [ROW] .Date), but it always worked. Finally, I found out that I need to create a set between <WeekSelectorCell, WeekViewModel> , because Options[] is an ObservableCollection of WeekViewModel
As I said, a long story, I do not need to use ClearBindings(view)