Is there a standered naming convention when making folders in a prism project ?
This works
ViewModals:
HelloWorldPageViewModel
View:
HelloWorldPage
App:
Container.RegisterTypeForNavigation<Views.HelloWorldPage >();
But for some reason , this does not work
I added the folling folders Login > Template >
ViewModals:
Login.Template.HelloWorldPageViewModel
View:
Login.Template.HelloWorldPage
App:
Container.RegisterTypeForNavigation<Views.Login.Template.HelloWorldPage >();
You have three options:
Change the naming conventions using the ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver. You can see an example in this blog post: http://brianlagunas.com/getting-started-prisms-new-viewmodellocator/
Or you can simply register your VM directly with ViewModelLocationProvider.Register<View, ViewModel>();
If you are using Xamarin.Forms simply provide the VM in the Container.RegisterTypeForNavigation<View, ViewModel>(); method
To the best of my knowledge Prism checks namepaces of ViewModels and Views.
So if your have a view it has to be under Views.Something , and if you want to have a viewmodel for it should be "ViewModels.SomethingViewModel"
Related
I have an Xamarin Application together with MvvmCross 5.7 and wanted to moved it completly to Xamarin Forms. It builds and starts as expected, but the first page isn't loaded.
I created the projects based this template: https://github.com/martijn00/MvxForms
Also I created a test project to see if something is wrong with my existing project: https://github.com/NPadrutt/XFTestProject
Can anyone point out what I am missing?
Either add a SplashScreen Activity who inherits from MvxSplashScreenActivity and with the method override:
protected override void TriggerFirstNavigate()
{
StartActivity(typeof(MainActivity));
base.TriggerFirstNavigate();
}
Or add these lines to the OnCreate Method in the MainActivity:
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
InitializeForms(bundle);
You don't neet to call startup.Start() in your MainActivity nor you need to init xamarin forms. It's done for you now (check RunAppStart method in mvvmcross sources for MvxFormsAppCompatActivity class).
From a quick glimpse at your GitHub repo, it looks like you're not decorating your view (i.e. WelcomView) with [MvxContentPagePresentation()] attribute (e.g. example from MvvmCross Playground). Add it in your WelcomeView.xaml.cs file and check if that helped
If it's a fresh project, you might want to consider using latest version of MvvmCross (v6). There's an awesome step by step guide to setup Xamarin.Forms with it by Nick Randolph
I know what View Engine is, I preferred to use Razor view engine just because of its simple syntax over ASPX engine. Inbuilt view engine performs almost all task for you, then in what scenario I should create my own view engine,
I googled it but getting answers for How to create it and not when and why to create it.
Can any one help me to describe the real time scenario?
For example, you can change the view files locations that Razor searches with the help of custom view engine.
Normally, in MVC these locations are searched for partial views:
// Part of the RazorViewEngine implementation from the Asp.net MVC source code
PartialViewLocationFormats = new[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/{1}/{0}.vbhtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/Shared/{0}.vbhtml"
};
Then add for example LayoutsPartialViews folder to Shared folder and add partial views which for example will be used only for layouts. And add for example ColorfuleHeader.cshtml to that location. And try to render that view via this:
#Html.Partial("ColorfulHeader");
Such exception will be throwned:
The partial view 'ColorfulHeader' was not found or no view engine
supports the searched locations. The following locations were
searched...:
So we must add this location to the searched locations. And for doing this we must create our custom view engine:
public class CustomLocationViewEngine : RazorViewEngine
{
public CustomLocationViewEngine()
{
PartialViewLocationFormats = new[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/{1}/{0}.vbhtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/Shared/{0}.vbhtml",
"~/Views/Shared/LayoutsPartialViews/{0}.cshtml",
"~/Views/Shared/LayoutsPartialViews/{0}.vbhtml",
};
}
}
Also, remember that the action invoker goes to each view engine in turn to see if a view can be found. By
the time that we are able to add our view to the collection, it will already contain the standard Razor View
Engine. To avoid competing with that implementation, we call the Clear method to remove any other
view engines that may have been registered, and then call the Add method to register our custom
implementation.
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomLocationViewEngine());
I have an ASP.NET vNext (5) project. I am trying to add two areas to the project. My question is, how do I register areas in vNext? The System.Web.Mvc namespace is gone, which is where AreaRegistrationContext was located. I started looking in the MVC source code on GitHub. I found the Area attribute. However, I'm not sure how to utilize it now.
Can someone please explain to me (or provide a link) of how to use Areas in ASP.NET vNext?
Thank you!
In vNext you register and configure the services you are going to use in Startup.cs. Area routes are added like normal routes. There is a sample here: https://github.com/aspnet/Mvc/blob/a420af67b72e470b9481d6b2eca29f7c7c2254d2/samples/MvcSample.Web/Startup.cs
You could add an MVC route for an area like this:
app.UseMvc(routes =>
{
routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}");
});
Or you could use a route attribute like this: [Route("[area]/Home")]
The [Area] attribute decorates controllers included in the area. It takes only one parameter, the name of the area. Here's an example: https://github.com/aspnet/Mvc/blob/a420af67b72e470b9481d6b2eca29f7c7c2254d2/samples/MvcSample.Web/Areas/Travel/Controllers/HomeController.cs
[Area("Travel")]
public class HomeController : Controller
{ //... }
Hi all i have created my code etc for the .h/.m that are all ready provided. But i would like to known how to add more because when i add a view controller to my storyboard. I can't have code in it i think what I'm looking for is called a second view controller .h/.m. I am creating a project in Xcode 4.2 and its a single view based application. I'm new to this but i think what i have said makes sense thanks for your time.
kind regards
open your project
press command+N to open the new file dialog
iOS > CocoaTouch
Class = YOUR_CLASS_NAME
Subclass of = SUBCLASS_TYPE (e.g. UIViewController)
etc.
How can I get the current view name regarding to current URL, in asp.net MVC 3 using Razor engine?
No idea why you would need to get the current view name but you could use the VirtualPath property inside a view. Normally it's more useful to know the current action or controller. But anyway, here's how to get the current view name:
#VirtualPath
and if you wanted to get only the filename:
#Path.GetFileName(Server.MapPath(VirtualPath))
and without the extension:
#Path.GetFileNameWithoutExtension(Server.MapPath(VirtualPath))
I've also tested this code, and I could do something with it.
But, I'm not sure if is this a good solution or not.
For example, I need to detect the Contacts view located in Home directory. So I wrote:
if (#Request.RawUrl == "/Home/Contacts")
{
// do something
}
You can get it from RequestContext.RouteData
specifically, its Values collection contains "controller" and "action" keys
i.e.
RequestContext.RouteData.Values["controller"]
RequestContext.RouteData.Values["action"]
ASP.NET Core's equivalent:
#ViewContext.ExecutingFilePath
Output is like this:
/Views/Shared/String.cshtml
The rendering of a view may involve one or more files (e.g. _ViewStart, Layouts etc).
This property contains the path of the file currently being rendered.
ViewContext.ExecutingFilePath Property