I am working on a Xamarin.iOS app and I am new to ReactiveUI.
I'm trying to bind some properties in a custom table cell that implements ReactiveTableViewCell
and IViewFor<>
.
The examples I have seen just show binding to the TextLabel.Text
, which works fine for me, but when trying to bind to other properties on the table cell that was generated in the UI designer, nothing binds/displays.
The setup is very similar to ReactiveTableViewSource-Sample however I am trying to bind to a label I placed using the designer rather than the default TextLabel.Text
.
Here is my call to bind the table to the custom tablecell.
ViewModel.WhenAnyValue(vm => vm.SearchResults)
.BindTo<AgentSearchResult, AgentSearchResultsTableCell>
(agentsTableView, 64, cell => cell.Initialize());
Here is my Initialize method in the custom tablecell.
public void Initialize()
{
this.WhenAnyValue(v => v.ViewModel.Name).BindTo
(this, v => v.lblName.Text); // Doesn't Work
this.WhenAnyValue(v => v.ViewModel.Name).BindTo
(this, v => v.TextLabel.Text); // Works
this.WhenAnyValue(v => v.ViewModel.Agency).BindTo
(this, v => v.lblCompany.Text);
this.WhenAnyValue(v => v.ViewModel.Phone).BindTo
(this, v => v.lblPhone.Text);
this.WhenAnyValue(v => v.ViewModel.Email).BindTo
(this, v => v.lblEmail.Text);
}
Ok, I was able to get this working. It was a rather simple fix but I just didn't see any examples/documentation for it.
The issue was that any items added with the designer were null.
Here is how I fixed it with Storyboards using the designer:
Update the binding in your ViewController for the TableView to include the CellKey.
ViewModel.WhenAnyValue(vm => vm.SearchResults).BindTo<AgentSearchResult, AgentSearchResultsTableCell>(agentsTableView, new NSString("AgentSearchResultsCell"), 64, cell => cell.Initialize());
After making these changes the databinding worked perfectly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.