我创建了一个 TAB 控件,如MVVMCROSS Tab链接中所述。
例如:我有两个选项卡 ViewModels “搜索和过滤”。
FilterViewModel:要在 View 中绑定的 Country 和 State 结果属性。
SearchViewModel:通过从 FilterViewModel 中选择的过滤器列出可用的结果以查看。
如何更新从 Filterviewmodel 属性更改的 Searchviewmodel SearchListing 功能?
编辑:我的带有 Messenger 代码的示例核心函数。但是缺少一些解决方法!请建议
public class SearchWOViewModel : MvxViewModel
{
private readonly ISearchService _serachwo;
private readonly IMvxMessenger _messenger;
public SearchWOViewModel(ISearchService search, IMvxMessenger Messanger)
{
_serachwo = search;
Search = new SearchViewModel(_serachwo);
Filter = new FilterViewModel(_serachwo, Search, Messanger);
}
private FilterViewModel _Filter;
public FilterViewModel Filter { get { return _Filter; } set { _Filter = value; RaisePropertyChanged(() => Filter); } }
private SearchViewModel _Search;
public SearchViewModel Search { get { return _Search; } set { _Search = value; RaisePropertyChanged(() => Search); } }
}
public class FilterViewModel : MvxViewModel
{
private readonly ISearchService _filterwo;
private readonly IMvxMessenger messenger;
private readonly MvxSubscriptionToken _token;
public FilterViewModel(ISearchService search, SearchViewModel searchViewModel,IMvxMessenger _messenger)
{
_filterwo = search; messenger = _messenger;
searchViewModel = SearchViewModel;
SiteDropDown();
EquipmentDropDown();
}
public void SiteDropDown() { String query = "UserSite"; _filterwo.UserSite(query, result => { SiteResult = result; messenger.Publish(new UpdateSearchResultsMessage(this)); searchViewModel.SearchListingWO(); }, error => { }); }
private List<DropDownEquipment> _siteresult;
public List<DropDownEquipment> SiteResult { get { return _siteresult; } set { _siteresult = value; RaisePropertyChanged(() => SiteResult); } }
public void EquipmentDropDown() { String query = "FillEquipment"; _filterwo.FillEquipment(query, result => { EquipmentResult = result; }, error => { }); }
private List<DropDownEquipment> _EquipmentResults;
public List<DropDownEquipment> EquipmentResult { get { return _EquipmentResults; } set { _EquipmentResults = value; RaisePropertyChanged(() => EquipmentResult); } }
private DropDownEquipment _SelectedSite;
public DropDownEquipment SelectedSite { get { return _SelectedSite; } set { _SelectedSite = value; RaisePropertyChanged(() => SelectedSite); } }
private DropDownEquipment _SelectedEquipment;
public DropDownEquipment SelectedEquipment { get { return _SelectedEquipment; } set { _SelectedEquipment = value; RaisePropertyChanged(() => SelectedEquipment); } }
}
public class SearchViewModel : MvxViewModel
{
private readonly ISearchService _WorkOrder;
public SearchViewModel(ISearchService search)
{
_WorkOrder = search;
SearchListingWO();
}
public void SearchListingWO() { String query = "WORKORDER"; _WorkOrder.Listingwo(query, result => Results = result, error => { }); }
private List<ListingWo> _results;
public List<ListingWo> Results { get { return _results; } set { _results = value; RaisePropertyChanged(() => Results); } }
private ListingWo _SelectedWO;
public ListingWo SelectedWO { get { return _SelectedWO; } set { _SelectedWO = value; RaisePropertyChanged(() => SelectedWO); } }
}
public class UpdateSearchResultsMessage : MvxMessage
{
public UpdateSearchResultsMessage(object sender) : base(sender) { }
}
请参考 MySampleTabCode中的示例代码。请建议/指导如何传递数据。