0

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 => { });
    }
}
theB
  • 6,450
  • 1
  • 28
  • 38
Kathir
  • 137
  • 3
  • 19

1 Answers1

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.

Community
  • 1
  • 1
Anthony Wu
  • 63
  • 1
  • 7
  • Thank you Anthony Wu. I have tried the sample Tab application and working good. But how to reload the tab contents from one tab selection to another. For ex: We want to reload the 'SEARCH tab' grid contents by 'Filter tab' drop down selection. – Kathir Sep 07 '13 at 05:20
  • Added to the answer instead. – Anthony Wu Sep 10 '13 at 05:51
  • Kindly check updated question. It shows the Unhandled exception while initializing the constructor in one of the tab control with json function calling with interface. Kindly suggest. – Kathir Sep 11 '13 at 09:33
  • Take a look at this one http://stackoverflow.com/questions/16142629/mvvmcross-calling-web-service-from-view-model?rq=1 – Anthony Wu Sep 15 '13 at 18:35
  • Thank you Anthony Wu. The issue is at constructor and it is resolved. I have gone through the above mentioned links for tab reloading, but still i can't make reloading. Kindly suggest. Sorry if my question is chilly. – Kathir Sep 16 '13 at 09:22
  • and take a look here http://forums.xamarin.com/discussion/552/monotouch-dialog-how-to-update-the-table-cell-refresh-the-data – Anthony Wu Sep 18 '13 at 19:05
  • Put your code to refresh the data in the viewwillappear or viewdidappear. And you can pass the data between each views by message as i mentioned previously or via local storage like SQL lite – Anthony Wu Sep 18 '13 at 20:08
  • still i am working the above and don't know how to pass the values between the Tab controls and re-call the SearchViewModel listingjson function from FilterViewModel ? I have tried (N=9 video) but nothing works well. Kindly help me out to solve the issue. – Kathir Sep 24 '13 at 11:24
  • I have updated the sample code for reference. Please check it. – Kathir Sep 24 '13 at 11:36
  • passing values between viewmodels http://slodge.blogspot.co.uk/2013/01/navigating-between-viewmodels-by-more.html or this http://forums.xamarin.com/discussion/3684/mvvmcross-passing-parameter. AS reagarding how to force a refresh for the view. You just need to refresh the data call in ViewWillAppear() – Anthony Wu Sep 24 '13 at 20:21
  • Also, as a suggestion. based on ur description, you shouldn't really use a Tab view. A Fly-out style view is much better for you need. There is a fly out component for ios on component store on xamarin. Also quite a few examples for android on github or this http://blog.neteril.org/blog/2013/04/19/fly-out-menu-xamarin-android/. Bascially the flyout menu is gonna be your filter page, and the mainpage is gonna be your search result page. – Anthony Wu Sep 24 '13 at 21:25
  • In your comment its mentioned that flyout for ios and android available but for windows 8 & windows Phone!!! My problem is how to fire the tab change event in MVXViewModel core project or how to call the another view model(search) SearchListingWO function from viewmodel(Filter) property selectionchange called?. – Kathir Sep 25 '13 at 05:43
  • just so let you know...flyout also exsit on windows phone. I just offer it as a suggestion. if you don't like can just ignore it and no need the "!!!!". As to your question(fianlly it's clear), i edited the answer page. If you have futher more questions please open a new page, that way more people can see it and help other than keep updating this page and only me coming back to help u. – Anthony Wu Sep 25 '13 at 06:49