ViewModelLocator is now responsible for connecting view models to views.
Uses an auto-wiring convention-based approach.
This commit is contained in:
parent
a7f9d2c73c
commit
14efed11a8
@ -1,6 +1,6 @@
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Services;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
@ -28,12 +28,13 @@ namespace eShopOnContainers
|
||||
{
|
||||
UseMockServices = Settings.UseMocks;
|
||||
|
||||
ViewModelLocator.Instance.UpdateDependencies(UseMockServices);
|
||||
ViewModelLocator.Initialize();
|
||||
ViewModelLocator.UpdateDependencies(UseMockServices);
|
||||
}
|
||||
|
||||
private Task InitNavigation()
|
||||
{
|
||||
var navigationService = ViewModelLocator.Instance.Resolve<INavigationService>();
|
||||
var navigationService = ViewModelLocator.Resolve<INavigationService>();
|
||||
return navigationService.InitializeAsync();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
using eShopOnContainers.Core.Models.Basket;
|
||||
using eShopOnContainers.Core.Models.Catalog;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@ -21,7 +21,7 @@ namespace eShopOnContainers.Core.Helpers
|
||||
|
||||
try
|
||||
{
|
||||
if (!ViewModelLocator.Instance.UseMockService
|
||||
if (!ViewModelLocator.UseMockService
|
||||
&& Settings.UrlBase != GlobalSetting.DefaultEndpoint)
|
||||
{
|
||||
foreach (var catalogItem in catalogItems)
|
||||
@ -54,7 +54,7 @@ namespace eShopOnContainers.Core.Helpers
|
||||
|
||||
try
|
||||
{
|
||||
if (!ViewModelLocator.Instance.UseMockService
|
||||
if (!ViewModelLocator.UseMockService
|
||||
&& Settings.UrlBase != GlobalSetting.DefaultEndpoint)
|
||||
{
|
||||
foreach (var basketItem in basketItems)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using Plugin.Settings;
|
||||
using Plugin.Settings.Abstractions;
|
||||
|
||||
@ -27,7 +27,7 @@ namespace eShopOnContainers.Core.Helpers
|
||||
private const string IdUrlBase = "url_base";
|
||||
private static readonly string AccessTokenDefault = string.Empty;
|
||||
private static readonly string IdTokenDefault = string.Empty;
|
||||
private static readonly bool UseMocksDefault = ViewModelLocator.Instance.UseMockService;
|
||||
private static readonly bool UseMocksDefault = ViewModelLocator.UseMockService;
|
||||
private static readonly string UrlBaseDefault = GlobalSetting.Instance.BaseEndpoint;
|
||||
|
||||
#endregion
|
||||
|
@ -1,4 +1,4 @@
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Core.ViewModels;
|
||||
using eShopOnContainers.Core.Views;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
@ -11,9 +12,7 @@ namespace eShopOnContainers.Services
|
||||
{
|
||||
public class NavigationService : INavigationService
|
||||
{
|
||||
protected readonly Dictionary<Type, Type> _mappings;
|
||||
|
||||
protected Application CurrentApplication
|
||||
protected Application CurrentApplication
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -21,13 +20,6 @@ namespace eShopOnContainers.Services
|
||||
}
|
||||
}
|
||||
|
||||
public NavigationService()
|
||||
{
|
||||
_mappings = new Dictionary<Type, Type>();
|
||||
|
||||
CreatePageViewModelMappings();
|
||||
}
|
||||
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
if(string.IsNullOrEmpty(Settings.AuthAccessToken))
|
||||
@ -100,7 +92,7 @@ namespace eShopOnContainers.Services
|
||||
|
||||
protected virtual async Task InternalNavigateToAsync(Type viewModelType, object parameter)
|
||||
{
|
||||
Page page = CreateAndBindPage(viewModelType, parameter);
|
||||
Page page = CreatePage(viewModelType, parameter);
|
||||
|
||||
if (page is LoginView)
|
||||
{
|
||||
@ -109,7 +101,6 @@ namespace eShopOnContainers.Services
|
||||
else
|
||||
{
|
||||
var navigationPage = CurrentApplication.MainPage as CustomNavigationView;
|
||||
|
||||
if (navigationPage != null)
|
||||
{
|
||||
await navigationPage.PushAsync(page);
|
||||
@ -125,40 +116,23 @@ namespace eShopOnContainers.Services
|
||||
|
||||
protected Type GetPageTypeForViewModel(Type viewModelType)
|
||||
{
|
||||
if (!_mappings.ContainsKey(viewModelType))
|
||||
{
|
||||
throw new KeyNotFoundException($"No map for ${viewModelType} was found on navigation mappings");
|
||||
}
|
||||
|
||||
return _mappings[viewModelType];
|
||||
var viewName = viewModelType.FullName.Replace("Model", string.Empty);
|
||||
var viewModelAssemblyName = viewModelType.GetTypeInfo().Assembly.FullName;
|
||||
var viewAssemblyName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", viewName, viewModelAssemblyName);
|
||||
var viewType = Type.GetType(viewAssemblyName);
|
||||
return viewType;
|
||||
}
|
||||
|
||||
protected Page CreateAndBindPage(Type viewModelType, object parameter)
|
||||
protected Page CreatePage(Type viewModelType, object parameter)
|
||||
{
|
||||
Type pageType = GetPageTypeForViewModel(viewModelType);
|
||||
|
||||
if (pageType == null)
|
||||
{
|
||||
throw new Exception($"Mapping type for {viewModelType} is not a page");
|
||||
throw new Exception($"Cannot locate page type for {viewModelType}");
|
||||
}
|
||||
|
||||
Page page = Activator.CreateInstance(pageType) as Page;
|
||||
ViewModelBase viewModel = ViewModelLocator.Instance.Resolve(viewModelType) as ViewModelBase;
|
||||
page.BindingContext = viewModel;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
private void CreatePageViewModelMappings()
|
||||
{
|
||||
_mappings.Add(typeof(BasketViewModel), typeof(BasketView));
|
||||
_mappings.Add(typeof(CatalogViewModel), typeof(CatalogView));
|
||||
_mappings.Add(typeof(CheckoutViewModel), typeof(CheckoutView));
|
||||
_mappings.Add(typeof(LoginViewModel), typeof(LoginView));
|
||||
_mappings.Add(typeof(MainViewModel), typeof(MainView));
|
||||
_mappings.Add(typeof(OrderDetailViewModel), typeof(OrderDetailView));
|
||||
_mappings.Add(typeof(ProfileViewModel), typeof(ProfileView));
|
||||
_mappings.Add(typeof(SettingsViewModel), typeof(SettingsView));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
@ -3,7 +3,7 @@ using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace eShopOnContainers.ViewModels.Base
|
||||
namespace eShopOnContainers.Core.ViewModels.Base
|
||||
{
|
||||
public abstract class ExtendedBindableObject : BindableObject
|
||||
{
|
||||
|
@ -1,9 +1,8 @@
|
||||
using eShopOnContainers.Core;
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Services;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eShopOnContainers.ViewModels.Base
|
||||
namespace eShopOnContainers.Core.ViewModels.Base
|
||||
{
|
||||
public abstract class ViewModelBase : ExtendedBindableObject
|
||||
{
|
||||
@ -28,14 +27,14 @@ namespace eShopOnContainers.ViewModels.Base
|
||||
|
||||
public ViewModelBase()
|
||||
{
|
||||
DialogService = ViewModelLocator.Instance.Resolve<IDialogService>();
|
||||
NavigationService = ViewModelLocator.Instance.Resolve<INavigationService>();
|
||||
DialogService = ViewModelLocator.Resolve<IDialogService>();
|
||||
NavigationService = ViewModelLocator.Resolve<INavigationService>();
|
||||
GlobalSetting.Instance.BaseEndpoint = Settings.UrlBase;
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync(object navigationData)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
using Microsoft.Practices.Unity;
|
||||
using eShopOnContainers.Core.ViewModels;
|
||||
using eShopOnContainers.Services;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using eShopOnContainers.Core.Services.Catalog;
|
||||
using eShopOnContainers.Core.Services.OpenUrl;
|
||||
using eShopOnContainers.Core.Services.RequestProvider;
|
||||
@ -9,54 +10,53 @@ using eShopOnContainers.Core.Services.Basket;
|
||||
using eShopOnContainers.Core.Services.Identity;
|
||||
using eShopOnContainers.Core.Services.Order;
|
||||
using eShopOnContainers.Core.Services.User;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace eShopOnContainers.ViewModels.Base
|
||||
namespace eShopOnContainers.Core.ViewModels.Base
|
||||
{
|
||||
public class ViewModelLocator
|
||||
public static class ViewModelLocator
|
||||
{
|
||||
private bool _useMockService;
|
||||
private readonly IUnityContainer _unityContainer;
|
||||
private static readonly IUnityContainer _unityContainer = new UnityContainer();
|
||||
|
||||
private static readonly ViewModelLocator _instance = new ViewModelLocator();
|
||||
public static readonly BindableProperty AutoWireViewModelProperty =
|
||||
BindableProperty.CreateAttached("AutoWireViewModel", typeof(bool), typeof(ViewModelLocator), default(bool), propertyChanged: OnAutoWireViewModelChanged);
|
||||
|
||||
public static ViewModelLocator Instance
|
||||
{
|
||||
get { return _instance; }
|
||||
}
|
||||
public static bool GetAutoWireViewModel(BindableObject bindable)
|
||||
{
|
||||
return (bool)bindable.GetValue(ViewModelLocator.AutoWireViewModelProperty);
|
||||
}
|
||||
|
||||
public bool UseMockService
|
||||
{
|
||||
get { return _useMockService; }
|
||||
set { _useMockService = value; ; }
|
||||
}
|
||||
public static void SetAutoWireViewModel(BindableObject bindable, bool value)
|
||||
{
|
||||
bindable.SetValue(ViewModelLocator.AutoWireViewModelProperty, value);
|
||||
}
|
||||
|
||||
protected ViewModelLocator()
|
||||
{
|
||||
_unityContainer = new UnityContainer();
|
||||
public static bool UseMockService { get; set; }
|
||||
|
||||
// Services
|
||||
_unityContainer.RegisterType<IDialogService, DialogService>();
|
||||
RegisterSingleton<INavigationService, NavigationService>();
|
||||
_unityContainer.RegisterType<IOpenUrlService, OpenUrlService>();
|
||||
_unityContainer.RegisterType<IRequestProvider, RequestProvider>();
|
||||
_unityContainer.RegisterType<IIdentityService, IdentityService>();
|
||||
public static void Initialize()
|
||||
{
|
||||
// Services
|
||||
_unityContainer.RegisterType<IDialogService, DialogService>();
|
||||
_unityContainer.RegisterType<INavigationService, NavigationService>(new ContainerControlledLifetimeManager());
|
||||
_unityContainer.RegisterType<IOpenUrlService, OpenUrlService>();
|
||||
_unityContainer.RegisterType<IRequestProvider, RequestProvider>();
|
||||
_unityContainer.RegisterType<IIdentityService, IdentityService>();
|
||||
_unityContainer.RegisterType<ICatalogService, CatalogMockService>();
|
||||
_unityContainer.RegisterType<IBasketService, BasketMockService>();
|
||||
_unityContainer.RegisterType<IUserService, UserMockService>();
|
||||
|
||||
_unityContainer.RegisterType<ICatalogService, CatalogMockService>();
|
||||
_unityContainer.RegisterType<IBasketService, BasketMockService>();
|
||||
_unityContainer.RegisterType<IUserService, UserMockService>();
|
||||
// View models
|
||||
_unityContainer.RegisterType<BasketViewModel>();
|
||||
_unityContainer.RegisterType<CatalogViewModel>();
|
||||
_unityContainer.RegisterType<CheckoutViewModel>();
|
||||
_unityContainer.RegisterType<LoginViewModel>();
|
||||
_unityContainer.RegisterType<MainViewModel>();
|
||||
_unityContainer.RegisterType<OrderDetailViewModel>();
|
||||
_unityContainer.RegisterType<ProfileViewModel>();
|
||||
_unityContainer.RegisterType<SettingsViewModel>();
|
||||
}
|
||||
|
||||
// View models
|
||||
_unityContainer.RegisterType<BasketViewModel>();
|
||||
_unityContainer.RegisterType<CatalogViewModel>();
|
||||
_unityContainer.RegisterType<CheckoutViewModel>();
|
||||
_unityContainer.RegisterType<LoginViewModel>();
|
||||
_unityContainer.RegisterType<MainViewModel>();
|
||||
_unityContainer.RegisterType<OrderDetailViewModel>();
|
||||
_unityContainer.RegisterType<ProfileViewModel>();
|
||||
_unityContainer.RegisterType<SettingsViewModel>();
|
||||
}
|
||||
|
||||
public void UpdateDependencies(bool useMockServices)
|
||||
public static void UpdateDependencies(bool useMockServices)
|
||||
{
|
||||
// Change injected dependencies
|
||||
if (useMockServices)
|
||||
@ -80,29 +80,31 @@ namespace eShopOnContainers.ViewModels.Base
|
||||
}
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
public static T Resolve<T>()
|
||||
{
|
||||
return _unityContainer.Resolve<T>();
|
||||
}
|
||||
|
||||
public object Resolve(Type type)
|
||||
{
|
||||
return _unityContainer.Resolve(type);
|
||||
}
|
||||
private static void OnAutoWireViewModelChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
var view = bindable as Element;
|
||||
if (view == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void Register<T>(T instance)
|
||||
{
|
||||
_unityContainer.RegisterInstance<T>(instance);
|
||||
}
|
||||
var viewType = view.GetType();
|
||||
var viewName = viewType.FullName.Replace(".Views.", ".ViewModels.");
|
||||
var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
|
||||
var viewModelName = string.Format(CultureInfo.InvariantCulture, "{0}Model, {1}", viewName, viewAssemblyName);
|
||||
|
||||
public void Register<TInterface, T>() where T : TInterface
|
||||
{
|
||||
_unityContainer.RegisterType<TInterface, T>();
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TInterface, T>() where T : TInterface
|
||||
{
|
||||
_unityContainer.RegisterType<TInterface, T>(new ContainerControlledLifetimeManager());
|
||||
}
|
||||
var viewModelType = Type.GetType(viewModelName);
|
||||
if (viewModelType == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var viewModel = _unityContainer.Resolve(viewModelType);
|
||||
view.BindingContext = viewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@ using eShopOnContainers.Core.Models.Catalog;
|
||||
using eShopOnContainers.Core.Services.Basket;
|
||||
using eShopOnContainers.Core.Services.User;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,14 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Collections.ObjectModel;
|
||||
using Xamarin.Forms;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.Core.Models.Catalog;
|
||||
using eShopOnContainers.Core.Services.Catalog;
|
||||
using System.Windows.Input;
|
||||
using System.Linq;
|
||||
using eShopOnContainers.Core.Services.Basket;
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Core.Services.User;
|
||||
|
||||
namespace eShopOnContainers.Core.ViewModels
|
||||
|
@ -1,5 +1,5 @@
|
||||
using eShopOnContainers.Core.Models.Navigation;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
using System.Threading.Tasks;
|
||||
@ -138,7 +138,7 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
await _basketService.ClearBasketAsync(_shippingAddress.Id.ToString(), authToken);
|
||||
|
||||
// Reset Basket badge
|
||||
var basketViewModel = ViewModelLocator.Instance.Resolve<BasketViewModel>();
|
||||
var basketViewModel = ViewModelLocator.Resolve<BasketViewModel>();
|
||||
basketViewModel.BadgeCount = 0;
|
||||
|
||||
// Navigate to Orders
|
||||
|
@ -4,7 +4,7 @@ using eShopOnContainers.Core.Services.Identity;
|
||||
using eShopOnContainers.Core.Services.OpenUrl;
|
||||
using eShopOnContainers.Core.Services.User;
|
||||
using eShopOnContainers.Core.Validations;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using IdentityModel.Client;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@ -133,10 +133,9 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
|
||||
public override Task InitializeAsync(object navigationData)
|
||||
{
|
||||
if(navigationData is LogoutParameter)
|
||||
if (navigationData is LogoutParameter)
|
||||
{
|
||||
var logoutParameter = (LogoutParameter)navigationData;
|
||||
|
||||
if (logoutParameter.Logout)
|
||||
{
|
||||
Logout();
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.Core.Models.Navigation;
|
||||
using Xamarin.Forms;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.Core.Models.Orders;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.Core.Services.Catalog;
|
||||
using eShopOnContainers.Core.Services.Basket;
|
||||
using eShopOnContainers.Core.Services.Order;
|
||||
|
@ -3,7 +3,7 @@ using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Core.Models.Orders;
|
||||
using eShopOnContainers.Core.Models.User;
|
||||
using eShopOnContainers.Core.Services.Order;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
using System.Threading.Tasks;
|
||||
@ -71,7 +71,7 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
|
||||
private void MockServices()
|
||||
{
|
||||
ViewModelLocator.Instance.UpdateDependencies(!UseAzureServices);
|
||||
ViewModelLocator.UpdateDependencies(!UseAzureServices);
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.BasketView"
|
||||
x:Class="eShopOnContainers.Core.Views.BasketView"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||
Title="Cart">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.CatalogView"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||
Title="Catalog">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
|
@ -47,7 +47,8 @@ namespace eShopOnContainers.Core.Views
|
||||
{
|
||||
base.OnBindingContextChanged();
|
||||
|
||||
_filterView.BindingContext = BindingContext;
|
||||
if (_filterView != null)
|
||||
_filterView.BindingContext = BindingContext;
|
||||
}
|
||||
|
||||
private void OnFilterChanged(object sender, EventArgs e)
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.CheckoutView"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||
Title="Checkout">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
|
@ -2,9 +2,11 @@
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.LoginView"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core">
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
|
||||
<ContentPage.Title>
|
||||
<OnPlatform
|
||||
x:TypeArguments="x:String"
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.MainView"
|
||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
||||
BarBackgroundColor="{StaticResource DarkGreenColor}"
|
||||
BackgroundColor="{StaticResource BackgroundColor}"
|
||||
BarTextColor="{StaticResource WhiteColor}">
|
||||
BarTextColor="{StaticResource WhiteColor}"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
|
||||
<TabbedPage.Title>
|
||||
<OnPlatform
|
||||
x:TypeArguments="x:String"
|
||||
|
@ -1,6 +1,5 @@
|
||||
using eShopOnContainers.Core.ViewModels;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace eShopOnContainers.Core.Views
|
||||
@ -32,17 +31,9 @@ namespace eShopOnContainers.Core.Views
|
||||
}
|
||||
});
|
||||
|
||||
var homeViewModel = ViewModelLocator.Instance.Resolve<CatalogViewModel>();
|
||||
await homeViewModel.InitializeAsync(null);
|
||||
HomeView.BindingContext = homeViewModel;
|
||||
|
||||
var basketViewModel = ViewModelLocator.Instance.Resolve<BasketViewModel>();
|
||||
await basketViewModel.InitializeAsync(null);
|
||||
BasketView.BindingContext = basketViewModel;
|
||||
|
||||
var profileViewModel = ViewModelLocator.Instance.Resolve<ProfileViewModel>();
|
||||
await profileViewModel.InitializeAsync(null);
|
||||
ProfileView.BindingContext = profileViewModel;
|
||||
await ((CatalogViewModel)HomeView.BindingContext).InitializeAsync(null);
|
||||
await ((BasketViewModel)BasketView.BindingContext).InitializeAsync(null);
|
||||
await ((ProfileViewModel)ProfileView.BindingContext).InitializeAsync(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.OrderDetailView"
|
||||
x:Class="eShopOnContainers.Core.Views.OrderDetailView"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||
Title="{Binding Order.OrderNumber}">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.ProfileView"
|
||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
Title="My profile">
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||
Title="My profile">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.SettingsView"
|
||||
x:Class="eShopOnContainers.Core.Views.SettingsView"
|
||||
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||
Title="Settings">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user