Reputation: 1070
I have downloaded an example from the MVVMcross framework which can be found here. When I build the UWP project it compiles and runs without any errors.
Now I am trying to remake the UWP project and I face a problem which is located in the following file: XPlatformMenus/XPlatformMenus.UWP/Views/Home/HomeView.xaml.cs.
At line 11 and 12 the class is calling a return of base.Viewmodel. Question: Where is this property comming from?
My thinking process:
From my understandings the application is trying to return a property named ViewModel of the HomeViewModel class.
But when you check the HomeViewModel class: XPlatformMenus/XPlatformMenus.Core/ViewModels/Home/HomeViewModel.cs (located in different project, references are made) there is no property ViewModel.
Well the HomeViewModel inherits from BaseViewModel: XPlatformMenus/XPlatformMenus.Core/ViewModels/Base/BaseViewModel.cs but there is neither a property called ViewModel. BaseViewModel inherits from MvxViewModel so that's where it must be comming from! Well no, I view the MvxViewModel class with Visual Studio I receive this from metadata:
namespace MvvmCross.Core.ViewModels {
public abstract class MvxViewModel : MvxNavigatingObject, IMvxViewModel
{
protected MvxViewModel();
public MvxRequestedBy RequestedBy { get; set; }
public void Init(IMvxBundle parameters);
public void ReloadState(IMvxBundle state);
public void SaveState(IMvxBundle state);
public virtual void Start();
protected virtual void InitFromBundle(IMvxBundle parameters);
protected virtual void ReloadFromBundle(IMvxBundle state);
protected virtual void SaveStateToBundle(IMvxBundle bundle);
}
}
This neither has a ViewModel property... When I use the "Go to definition" function on the ViewModel property in Visual Studio she leads me to MvxWindowsPage:
using MvvmCross.Core.ViewModels;
using MvvmCross.Core.Views;
using MvvmCross.Platform.Core;
using MvvmCross.WindowsUWP.Views.Suspension;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace MvvmCross.WindowsUWP.Views
{
public class MvxWindowsPage : Page, IMvxWindowsView, IMvxView, IMvxDataConsumer
{
public MvxWindowsPage();
public IMvxWindowsFrame WrappedFrame { get; }
public IMvxViewModel ViewModel { get; set; }
protected IMvxSuspensionManager SuspensionManager { get; }
public void ClearBackStack();
protected virtual IMvxBundle LoadStateBundle(NavigationEventArgs e);
protected override void OnNavigatedFrom(NavigationEventArgs e);
protected override void OnNavigatedTo(NavigationEventArgs e);
protected virtual void SaveStateBundle(NavigationEventArgs navigationEventArgs, IMvxBundle bundle);
}
}
Which, indeed, has a property ViewModel. But I dont get how the HomeView knows about this class because I dont see where it gets set in the inherit path..
Upvotes: 0
Views: 259
Reputation: 3147
base.ViewModel refers to the class HomeView (in which it is used) which derives from BaseView.
In HomeView.xaml:
<local:BaseView
x:Class="XPlatformMenus.UWP.Views.HomeView"
Upvotes: 2