User Profile & Activity

Jack Member

Hi Domingo.

To implement searching, you need to provide a custom view controller for the selection list.

[ImportBinding(typeof(CategoryListBindingProvider))][RegisterNavigation(DeviceKind.Phone)]
[Register("CategoryListViewController")]
public partial class CategoryListViewContoller : UITableViewController<CategoryListViewModel> { public CategoryListViewContoller() : base("CategoryListView", null) { } protected override void InitializeView() { base.InitializeView(); this.RegisterViewIdentifier("SearchTableView", this.SearchDisplayController.SearchResultsTableView); } public override bool AllowSearching { get { return true; } } public override ChoiceInputMode ChoiceInputMode { get { return ChoiceInputMode.Single; } } public override TableViewInteraction InteractionMode { get { return TableViewInteraction.ChoiceInput; } } }


And don't forget to specify some properties for SelectionInput attribute in your form metadata, such as ReuseExistingViewContext and NavigationTargetIdentifier. It will ensure the form builder to use your view controller, instead the default one.

[SelectionInput(SelectionMode.Single, DisplayMemberPath = "Name", ListSourceType = typeof(CategoryListViewModel), ReuseExistingViewContext = true, NavigationTargetIdentifier="CategoryListViewController")]
public static string Category;


Hope this helps. You also can get the sample for this scenario from here: http://git.intersoftpt.com/projects/CROS-SUPP/repos/enable-searching-in-selection-form/browse.

Feel free to discuss it further if you have any other thought.


Kind Regards,

Jack
Posted: March 27, 2014 2:41 AM
Hi Fabian.

If you want to bind the same view model on multiple views, you need to register the name for each view, differentiating it from the other views. Later, the name will be used as the navigation target. See the following code.

// For iOS
[RegisterNavigation("FirstTab")] public partial class FirstViewController : UIViewController<SharedViewModel> { }

// For Android
[RegisterNavigation("FirstTab")]
public class FirstFragment : Fragment<SharedViewModel>
{

}

// For WinPhone
[ViewModelType(typeof(SharedViewModel))]
[RegisterNavigation("FirstTab")]
public partial class FirstTab : PhoneApplicationPage
{

}

// For WinRT
[ViewModelType(typeof(SharedViewModel))]
[RegisterNavigation("FirstTab")]
public sealed partial class FirstTab : LayoutAwarePage
{

}


Then while initializing the tab items on your parent's view model, you need to specify the navigation target, which contains the child's view model type and the target name. See the following code.

public class TabViewModel : MultiPageViewModelBase
{
    public TabViewModel()
    {
        var items = new List<NavigationItem>();
        items.Add(new NavigationItem("First Tab", new NavigationTarget(typeof(SharedViewModel), "FirstTab")));
        items.Add(new NavigationItem("Second Tab", new NavigationTarget(typeof(SharedViewModel), "SecondTab")));
        items.Add(new NavigationItem("Third Tab", new NavigationTarget(typeof(SharedViewModel), "ThirdTab")));
        this.Items = items.ToArray();
    }
}

Hope this helps. I also attached a sample solution for this scenario.

Feel free to discuss it further if you have any other thought.


Kind Regards,

Jack

Posted: March 26, 2014 10:15 PM

Hi Fabian.

You can pass any parameter to child view models from a tabbed page in 2 ways.

1. You can pass the parameter while initializing the tab items. You can specify it from the constructor of the parent's view model. See the following code.
public class TabViewModel : MultiPageViewModelBase{
        public TabViewModel()
        {
            var parameter1 = "Simple Page";
            var parameter2 = "About Page";
            var items = new List<NavigationItem>();
            items.Add(new NavigationItem("Simple Page", new NavigationTarget(typeof(SimpleViewModel), new NavigationParameter(parameter1))));
            items.Add(new NavigationItem("About", new NavigationTarget(typeof(AboutNavigationViewModel), new NavigationParameter(parameter2))));
            this.Items = items.ToArray();
        }
}

2. The second technique is the dynamic one. You can perform any logic based on your scenario to provide the parameter and pass it to the child's view model. Simply, you only need to override the ShouldNavigate method from the parent's view model. See the following code.

public class TabViewModel : MultiPageViewModelBase
{
        public override bool ShouldNavigate(NavigationTarget target)
        {
            // Perform your own logic here
            if (target.Type == typeof(SimpleViewModel))
                target.Parameter.Data = this.Data1;
            else
                target.Parameter.Data = this.Data2;
            return base.ShouldNavigate(target);
        }
}

Hope this helps. Feel free to discuss it further if you have any other thought.


Kind Regards,

Jack


All times are GMT -5. The time now is 10:34 PM.
Previous Next