Tab Control in MVVM CROSS

2019-04-17 08:11发布

问题:

We are developing an application that supports WP, Android & iOS operating systems using Xamarin framework.

Need to create two tabs Filter & Search, using filter tab will select some values from drop down, date picker and load the listing grid of search tab. But I couldn't able to find a sample application for creating tab control in MVVM CROSS (Portable Library Class).

ViewModel Class:

 public class SearchWOViewModel : MvxViewModel
{
    public readonly ISearchWOService _serachwo;
    public SearchWOViewModel()
    {
        Filter = new FilterViewModel(_serachwo);
        Search = new SearchViewModel(_serachwo);
    }

    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
{
   public FilterViewModel(ISearchWOService search)
   {
      _filterwo = search;
      SiteDropDown();
   }
    private string _SiteResult;
    public List<DropDownEquipment> SiteResult
    {  get { return _SiteResult; } set { _SiteResult = value;  } } 

    public void SiteDropDown()
    {
       String query = "UserSite";
      _filterwo.FillUserSite(query, result => SiteResult = result, error => { });
    }
}

public class SearchViewModel : MvxViewModel
{
    //How to call the service and load the listing grid while loading the page
    private readonly ISearchWOService _serachwo;
    public SearchViewModel(ISearchWOService search)
    {
        _serachwo = search;
        SearchListingWO();
    }

    private List<ListingWo> _results;
    public List<ListingWo> Results { get { return _results; }  set {   _results = value;  RaisePropertyChanged(() => Results);   } }

    public void SearchListingWO() // Want to reload this function once site dropdown changes
    {
        String query = "x/x/INDIA/SA/WORKORDER"; 
        _serachwo.Listingwo(query, result => Results = result,error => { });
    }
}

回答1:

Take a look at Stuart Lodge's N+1 days of MVVMCross Link Here

N=25 - Tabs (N+1 Days of MvvmCross)

edit: Some quick thought. Use message(N=9 video) to pass the selected filter option from 'Filter tab' to 'Search tab'. When 'Search tab' received the message, update(filter) the binding collection accordingly.

edit2: "My problem is how to fire the tab change event in MVXViewModel core project " iOS: SelectedViewController = ViewControllers[tabIndex];
Android: how to change tab of a tabactivity from an activity started by the tabactivity ? or change current tab Do all these in the VIEW code or bind the property to the viewmodel.