Love this framework thus far.
That said, hit my first roadblock. I have created an MvvmCross-based library (actually a few libraries) that performs login services that will be used across multiple cross-platform applications of the same family. What I can't quite figure out is how to plug these login libraries into my other applications (which will also be using MvvmCross). I want to be able to re-use the same ViewModels and Views across these apps.
Assume that I've read and watched a lot of slodge's videos. :) Which are very good.
I think MvvmCross with two core libraries was about the closest thing to what I'm trying to do, which is just smash MvvmCross projects together and make it all magically work. But going by that post, which had some inconsistencies in the code samples, I've been unable to get this working.
There are 2 methods in Setup which tell mvvmcross where to look for Views and ViewModels. If you override these then the system should find your views and view models.
protected virtual Assembly[] GetViewAssemblies()
{
var assembly = GetType().Assembly;
return new[] {assembly};
}
protected virtual Assembly[] GetViewModelAssemblies()
{
var app = Mvx.Resolve<IMvxApplication>();
var assembly = app.GetType().Assembly;
return new[] {assembly};
}
Beyond this, the only additions to this that I'm aware of are that you might need:
to give wp some extra help in finding the xaml urls for any views which are in additional assemblies - by default mvx only looks for the xaml uri in /views, not in any other folder in any other assembly. One way to provide the xaml urls is to add a MvxPhoneViewAttribute within the View's c# file, another is to override the MvxPhoneViewsContainer to make it provide custom urls.
to adjust some of the android project settings in order to get resources shared from libraries to main project (although this functionality has gotten much better within xamarin.android this year.
Related
I have created a new solution for my MvvmCross app that supported Windows Store and I want to support UWP on Windows 10. I have moved over the PCL successfully, but I am having problems getting the basic UWP app working using a sample provided by MS (NavigationMenu) which uses the SplitView and the AppShell pattern they are recommending for the new navigation/command model. I referenced a helpful blog post (http://stephanvs.com/implementing-a-multi-region-presenter-for-windows-10-uwp-and-mvvmcross/), which gave me some guidance on how to integrate mvvmcross into the AppShell, but startup is failing because the AppShell does not have a valid Frame defined. Frame is a read-only property, and I have been unable to see where this is being set up.
I am using the standard AppShell implementation from the NavigationMenu with the following changes as recommended in the blog post:
public sealed partial class AppShell : MvxWindowsPage // was Page
public Frame AppFrame { get { return this.Frame; } } // was this.frame
Except for code after the error, there are no differences in the setup. In looking at the MvxWindowsPage implementation, there doesn't seem to be anything special as it still invokes the Page initialization. Is there something obvious I am missing?
So the link to the blogpost is correct, in other words you'll need to use MultiRegions from MvvmCross to get this working.
But what the blogpost doesn't show is a complete working version...
I've added one on my github here:
https://github.com/Depechie/MvvmCrossUWPSplitView
Some pointers to take away, like I said in the comments.
Your view where the SplitView will be present, needs to have a property to return a valid Frame to look for while injecting new views. This can be returned like this return (Frame)this.WrappedFrame.UnderlyingControl; found in the code here https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/FirstView.xaml.cs#L13
Than all views you want to load up in the SplitView will need to reference to the region you defined in that SplitView, in my case I named it FrameContent as seen here https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/FirstView.xaml#L48
So use that name for the region attribute in all to be loaded views like so [MvxRegion("FrameContent")] example here https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/SecondView.xaml.cs#L7
I see what you're trying to do with the SplitView template that's provided by Microsoft. There is however a mismatch between things managed by MvvmCross and UWP.
By default MvvmCross maps ViewModels to Views based on naming conventions. What you are trying to do is use a view 'AppShell' (which is derived of Windows.UI.Xaml.Controls.Page) that doesn't adhere to the default MvvmCross convention.
The way I choose to implement this SplitView (Hamburger) functionality is by deleting the provided AppShell class entirely. I then created a new view named HomeView (since I have a ViewModel with the name HomeViewModel) and added the SplitView control there as described in the post you mentioned above.
For completeness I've created a Gist with the App.xaml.cs and HomeView.xaml as you requested. You can find them here: https://gist.github.com/Stephanvs/7bb2cdc9dbf15cb7a90f
I have a command that shows a view model:
private void DoShowImportCommand()
{
this.ShowViewModel<GeometryImportViewModel>();
}
but I only want to execute it if that view model isn't already shown. Is there a way to
detect if that view model is already on screen and if so don't execute the command?
MvvmCross doesn't track this by default - what is currently shown depends on the UI and can be interpreted in different ways in different situations (popups, tabs, pivots, dialogs, back stacks, etc)
If you want to track this in your own application, you could do it using UI project components (e.g. custom presenters) or you could do it using a shared code component - e.g. you could add "alive" tracking to the Views/ViewModels (see the N=42 video on http://mvvmcross.blogspot.com) and could then use some service to track which viewmodels are shown.
I am trying to understand how MvvmCross manages memory on Windows Phone.
I try to mark my view and viewmodel as IDisposable, but the Dispose method is never called.
What I need to do is to make sure that I can free up some resources while my app is running location tracking in the background.
Christian
In MvvmCross:
each View references its ViewModel
the platform-specifiic operating system decides when to dereference the View - when this occurs it normally calls a method on the View (but this does depend on whether the view is a page, a tab, a flyout, a dialog, a custom control, etc)
the .Net or Mono Garbage Collector then decides when to collect both the Views and ViewModels from memory
If you want to do more "active" monitoring of when the View is visible for "page-level" Views, then you need to monitor "page-level" View-specific events like:
ViewDidAppear \ ViewDidDisappear \ removeFromParentViewController (iOS)
OnResume \ OnPause`OnFinish` (Droid)
OnNavigatedTo`OnNavigatedFrom` (Windows)
A generalised form of these events can then be easily called on a custom interface on your ViewModel (this can be IDisposable if you want - this is your application code).
Update: I have blogged about this and published a sample - see http://slodge.blogspot.co.uk/2013/11/n42-is-my-viewmodel-visible-can-i-kill.html
There's a bit more info on this in:
ViewModel LifeCycle, when does it get disposed? (see "There's no easy universal way to know when to dispose the ViewModel - especially once you start mixing and matching ViewModel presentation styles to include navigations, tabs, splitviews, flyouts, fragments, lists, etc. and as you include more and more platforms")
https://github.com/MvvmCross/MvvmCross/wiki/View-Model-Lifecycle#viewmodel-deactivation-activation-and-destruction
How could I map my Linq-to-Sql generated entities (DTO’s) to my domain entities? The problem is that I can’t map the associations because they are not of the same type. The DTO’s uses EntitySet and EntityRef and my domain entities uses IList and T.
I’ve looked at some blog post: Ian Cooper's architecting-linq-to-sql-applications-part-5 and digital_ruminations linq-to-sql-poco-support but they don’t fit my needs. I like some kind of generic converter class to handle the mapping.
Now I do something like this:
public IList<Entities.Customer> GetAll()
{
try
{
return _custConverter.Convert(base.GetEntities());
}
But the Convert method only converts the basic properties not the associations.
Any ideas how I can do this the best way?
You might want to look into AutoMapper. It does a great job of mapping properties automatically out of the box and supports extensive customization, such as custom converters, which I think could be used to make Lists out of your EntitySets.
Update:
The official project site and compiled releases are found in CodePlex (same link as above).
Code is SVN hosted at Google Code
Discussiong group is hosted at Google Groups
Accouncement and overview of features at Jimmy Bogart's blog post
quick question, I've been looking for a simple logging tool for AS3 projects (I do not want any Flex dependencies) and my impression so far has been that there is no actively developed project.
What I need is basic logging, and adapters to allow me to send logging to file (using AIR and a LocalConnection maybe) and maybe send to html div etc.
Anyone have any opinions on a simple, light weight project?
We have recently started a project called AS3Commons that contains an early implementation of an AS3 Logging framework. We're aiming to provide a Logging abstraction API that allows you to plug in adapters for other logging frameworks. We also have a built-in logger that logs using trace.
It's usage is similar to other logging frameworks.
private static var logger:ILogger = LoggerFactory.getLogger("com.domain.Class");
Check it at http://code.google.com/p/as3-commons/
Any feedback is appreciated.
This is the best as3 logger by far!!!!
http://arthropod.stopp.se/
There is a standard Logging API in AS3. You can set it up to log to different targets. For instance, if you're using AIR, you could get it to log to a file using the FileTarget in as3corelib.
Setting up:
var logFile:File = File.applicationStorageDirectory.resolvePath("logs/logfile.log");
var logTarget:FileTarget = new FileTarget(logFile);
logTarget.filters = ["path.to.Class"];
logTarget.level = LogEventLevel.ALL;
logTarget.includeDate = true;
logTarget.includeTime = true;
logTarget.includeCategory = true;
logTarget.includeLevel = true;
Log.addTarget(logTarget);
Logging:
var log:ILogger = Log.getLogger("path.to.Class");
log.info("testing the logging...");
I'm always surprised at the number of people who haven't heard of Arthropod. It does everything you described and more. Including password encrypted connections. Arthropod is also set up in a way that it is very easy to make quick edits to the class for your specific needs.
I've got a Flash-friendly logging project going. It's nothing big (yet?) but it's light and handy. It does (optionally) take advantage of Arthropod (a great project) but you can pretty easily shoot the output anywhere you like. It works similarly to the Flex framework so if you are familiar with that then the transition would be painless.
You can read about the project and download the goods here.
MonsterDebugger has more options than it sounds like you're looking for. But it is small and has some very handy features. Including instance inspection, editing properties, calling methods remotely from the air console, and browsing/editing the display tree.
http://monsterdebugger.com/
They made a game so you could learn the debugger, its great.
I found the best solution for me is combining as3commons-logging with Arthropod, like so:
LOGGER_FACTORY.setup = new SimpleTargetSetup(mergeTargets(new TraceTarget(), new ArthropodTarget()));
Then, if you have a client who is having issues but can't tail the flashlog, they can just fire up Arhtropod. Awesome!