0

I am using PRISM with xamarin forms, and I like to declare my viewmodels in the XAML,

xmlns:local="clr-namespace:MyProyect.ViewModels" 

……

<ContentPage.BindingContext>
    <local:RegistroPageViewModel />
</ContentPage.BindingContext>

so I can have XAML intellicense, in this sample my RegistroPageViewModel constructor have one parameter beacause it need for the base class but I don't know how to pass it within the xaml

public class RegistroPageViewModel : ViewModelBase
{
    public RegistroPageViewModel(INavigationService navigationService):base(navigationService)
    {
        registro = new RegistroInfo();
        Title = "Perfil de usuario";
    }

My specific question is: How can I still using XAML viemodels's declaration if the viewmodel have a parameter ? how can I pass a parameter in the XAML declaration?

thnaks in advance

KillemAll
  • 633
  • 1
  • 10
  • 25
  • You might want to upvote here and the linked resharper issue: https://stackoverflow.com/questions/36941300/how-to-provide-intellisense-with-the-datacontext-type-in-a-resharper-plugin – Haukinger Feb 28 '20 at 06:54

2 Answers2

0

For XAML to know about ViewModel, enable XamlC and Compiled Bindings. Documentation provides how to enable and use them properly.

XamlC checks for general compile time errors like property names and open-closing matching tags etc...

Compiled Bindings checks for existence of any property that is bound

memsranga
  • 1,088
  • 7
  • 13
0

You can use the view model locator (ViewModelLocator.AutowireViewModel="True") to have the view model created for you with all dependencies automatically injected.

Setting the view model as design data context (d:DataContext={d:DesignInstance local:RegistroPageViewModel}) should give you intellisense.

Haukinger
  • 10,420
  • 2
  • 15
  • 28