state handling in windows 8 using mvvmlight - windows-8

Implementation of state handling in windows 8 using mvvmlight
Is there any method avilable in mvvmligt to manage states in WinRT? How I can duplicate the functionality of default Suspensionmanager by using WinRT? And the second one is about managing navigation cycle ie if I navigated from page A - > B. and the go for suspend and shutdown state. When I re start the application in need to open page B. and while presses back key I need to load A. How I can effectively implement this using MVVM light in my WinRT application?

These aren't really MVVM Light functionality. You'll need to do these yourself.
One option would be to create your own navigation service (see example here). The navigation service could use the suspension manager to build/manage a breadcrumb trail for the application. If you added an additional method:
public void GoToMostRecentPage()
{//blah}
You'd be able to call this method in the app start-up and take the user to the appropriate page.
I'd stick with the SuspensionManager. If you want to make it more MVVM friendly you can wrap it in a service that is injected into your viewmodels as required.

You might be interested in the open-source Okra App Framework that you can get from NuGet or the CodePlex site I linked to above. It is designed from the ground up to work great with Windows 8 and the MVVM pattern (and you can still use your MVVM Light base classes).
It has a navigation manager that automatically handles everything you mentioned above - managing the application's navigation stack, persistence of the stack on application suspension/termination and even allows view models to persist their own state via a simple interface (like how the SuspensionManager works for pages).
(disclaimer: I am the lead developer on this project)

I wrote this originally for WP7 and have been updating for Win8 RT. It allows you to attach attributes to properties you want to keep in your view models, then the PersistenceManager dehydrates them (serialized to file) when the app is suspended and rehydrates when it resumes.
There are examples for WP7 and Win8, basic MVVM pattern and MVVM Light
Obelisk

Related

How can I determine if my Cocoa Desktop application is on the list of apps to be opened at login?

I am developing a SandBoxed Cocoa Application. I have successfully implemented the Launch at login feature by using the Core Foundation function:
SMLoginItemSetEnabled
I have based the implementation on This tutorial
But now I need a way to determine if my app is set to be launched at login, so that I can show the button in the appropriate position upon launch. I would expect a similar Core Foundation function to find out if a bundle identifier is on the list of login items, but I didn't find it.
Another problem is that, by using this Core Foundation approach, although it is recommended by Apple, my app is still inconsistent with the "Open at Login" tick in my application dock menu.
You can do it using the functions in the LSSharedFileList.h header, which is in LaunchServices.framework, which is in CoreServices.framework. As far as I can tell, Apple hasn't documented this stuff except in the header comments, but that's probably enough. The basic outline is that you first create a LSSharedFileListRef using the function LSSharedFileListCreate for the list type kLSSharedFileListSessionLoginItems. Then copy a snapshot of the list (which is a CFArrayRef) using LSSharedFileListCopySnapshot. Then for any item in the array, you can get its URL using LSSharedFileListItemCopyResolvedURL. That last function requires Mac OS X 10.10 or later, while I think the others date back to 10.5.
By the way, the docs on SMLoginItemSetEnabled say that it's for setting an embedded helper app as a login item, but it sounds like you're talking about a freestanding app.
Apple's sandbox documentation says:
With App Sandbox, you cannot create a login item using functions in the LSSharedFileList.h header file. For example, you cannot use the function LSSharedFileListInsertItemURL.
But maybe you can still use the shared file list functions on a read-only basis.

Can a HTML/WinJS View use a user control built in XAML/C#?

I am hesitant to develop a Windows Phone app in the HTML/WinJS Universal App space because of the difficulty of building complex user controls. Before I go the XAML/C# route, I would like to find out if it is possible to use a user control built in XAML/C# inside of an HTML/WinJS view?
My initial feeling is that it is not possible due to XAML parsing not being available in the HTML space, but I am not certain that this is the case. Any thoughts?
Also, I am not interested in 3rd party solutions such as Xamerin. I am really trying to see if this is possible from a native approach.
No. The HTML and Xaml UI stacks in the Windows Runtime are separate and cannot be mixed. You can call non-UI C# or native Windows Runtime Components from JavaScript.
You can include HTML in a Xaml WebView, but there is no reverse hosting.
--Rob

Implementing State handling in windows 8 using MVVM Light

How i can implement state handling (running / resume / Terminate states ) using mvvm light. The major issue i a facing is with Navigation. I am totally uncontrolled with the navigation stack. How i can effectively manage this with MVVM Light.
Start a new project using either the GridView or SplitView templates and take a look at SuspensionManager.cs in the Common folder. It has a method called RegisterFrame which, when called, starts tracking all of the navigation events from the frame and attempts to save off and restore state when the application suspends and resumes.
The applications main frame is registered with the SuspensionManager in App.OnLaunched (App.xaml.cs) and Saving is done in App.OnSuspending.
Finally, take a look at LayoutAwarePage.cs, also in the Common folder. You can inherit from LayoutAwarePage to get Portrait and Snapped design time support. It also attempts to handle navigation state caching by leveraging the SuspensionManager. So, no matter whether your page is navigated to from another page or as part of a resume, the virtual method LoadState is called with the correct data.
Obviously this pattern is managing navigation state directly in the page itself, but you could tweak this pattern to create a sort of "SuspensionService" that your ViewModels could leverage in the same way.
You might be interested in the open source Okra App Framework that is freely available on CodePlex and NuGet (disclaimer: I am the lead developer on this project). This has been designed from the ground up for Windows 8 applications, in particular those that use the MVVM pattern (and you can still use the MVVM Light base classes to define your view-models).
Of particular interest it includes,
A navigation manager that understands the Windows 8 navigation model
A navigation stack that can automatically persist its state upon application termination
A mechanism for view-models to persist their own state (via a simple interface)
Automatic view and view-model construction and wiring up (by default using MEF attributes)

Metro Style Apps: WinJS a must?

Yesterday I have started developing my first Metro style App using JavaScript.
I've used one of those templates in Visual Studio 2011. This project template comes with a bunch of generated code which relies heavily on WinJS. The whole structure reminds of the ASP.NET with its Views and corresponding Code Behind files. There is also a navigator.js file which is responsible for the navigation between the Views. The whole data resides in the data.js and can be retrieved using different functions.
I worked with backbone.js and I found its concepts like MVC structure and routing pretty cool. My question is basically if you can implement such a Metro style App using backbone.js?
Can I eliminate WinJS and just start from scratch? Should I try to integrate backbone.js into the current structure? What would it look like then? Are there any restrictions for using third party JavaScript frameworks? Should I leave the generated structure as it is?
What are the best practices and patterns developing Metro Style Apps with JavaScript?
Thanks
You can use any JavaScript framework you like within a Metro-style JavaScript application. See this related question about jQuery:
jQuery and Windows 8 JavaScript Metro Style Apps
The WinJS framework performs a couple of functions, the first is a set of non-UI APIs for managing and manipulating data, making service requests etc ... These are easily replaced with other JavaScript frameworks. The second is the UI layer, here you might struggle a bit. The WinJS UI has been designed to follow the Metro Design Language. If you replace it with your own UI layer (using jQuery UI for example) your application will just not look right.
Personally I would use WinJS for the UI layer and to integrate with the runtime (state persistance, app switching etc...), but use a more standard JavaScript library, such as Backbone or Knockout for the bulk of my code to ensure portability.
I use Knockout js and Require js for MVVM. For visual effects, I use jQuery.
My data-main looks like a bit this:
(function () {
"use strict";
var app = WinJS.Application;
app.onactivated = function (eventObject) {
require(["/scripts/knockout"], function(ko){
// My knockout viewModel and data binding goes here
});
};
app.start();
})();
If you prefer Backbone in stead, I guess the setup would be similar.

Screenflow based application in Adobe Flex/Flash

I'm searching for some code samples for my Flash application. The app is based on screen-flows , i.e each screen is defined with some visual elements with some buttons which have async events associated with them(consuming web services basically). The buttons also have functionality to go back and forth between screens and jump to any screen. I want to define all of the visual elements and the functionality of the events in a XML file. Thus the model, view and controller are all in the XML. Does any framework allow this like Pure MVC? Where can I find some examples of this kind of functionality that I want?
There's a Flash implementation of Heirarchical State Machines here, which mentions XML and Flow Control:
http://code.google.com/p/troyworks/
(Note: There's a very slick screencasting application called Screenflow which may lay claim on that particular term these days...)