Why does NavigationService on Silverlight/WP7 uses Strings over Classes? - wpf

Given that C# is a leans more towards a strongly typed language, why did the designers chose navigation based on URIs over Classes?
NavigationService.Navigate(new Uri("/MyPage.xaml", UriKind.Relative))
fails at run time if MyPage is missing.
If there were a method that support passing a PhoneApplicationPage as a argument like
NavigationService.Navigate(new MyPage());
Navigation related errors can be caught at compile time.
Why was this not an inherent design in Silverlight/WP7 ?

Only the WP7 dev tools team can say for sure, but absent their input, I'll give it my best shot. My guess is that it arises out of using a plug-in framework for client application development. Web Silverlight doesn't even really have the concept of navigation. You can switch frames in and out of the applications main frame, but that's not really navigation persay. So, when they were asked to use Silverlight as a client application tool for WP7, they had to decide how they were going to navigate around.
The most obvious way to solve the navigation problem, if you're a team that's been building internet applications, is to make something as close to the internet model as possible. This allows developers to carry internet applications to the browser and do minimal rewrites of their code. Think about it, if you had a web application that used relative URLs to move between application pages, your WP7 could reuse most of that navigation logic with only slight modifications to use the new NavigationService. This also minimizes the changes from core Silverlight that the WP7 version has to make, making everything easier to keep synchronized between platforms.
It obviously isn't the best way of doing things, and it makes state maintenance between pages a royal pain in the ass, but I can at least see why they decided to do it this way. The main flaws, in my experience, are the runtime checking of navigation destinations (instead of compile time with classes), passing parameters (every page needs an OnNavigatedTo that parses out variables) and maintenance of non-trivial objects between pages (I've taken to just using Singletons to hold relevant objects as a sort of poor-man's cache). I'm hoping for at least some modification to the navigation paradigm in 7.5 or 8, but I'm not holding my breath.

This navigation model was inherited from Silverlight on the desktop (and WPF before it). It's important to note: this is not a String-based model, but rather a URI-based model. The difference here is key: we're not talking about an arbitrary string to point to some XAML, we're talking about a universal locator for a resource that is a page within the application. By addressing navigation this way, your application actually has more than one entry point -- any URI within the application can be a valid entry point. And by making navigation URI-based, you ensure that the "state" of your application as it relates to what you're looking at can be serialized, accessed at any time from any direction, etc.
Imagine, for example, that you have a link on a webpage (or in an email, or anywhere else) that you want to open in your application. Click the link, and because the URI fully describes the resource that the application should display (e.g. an item in a catalog, filters on a search, etc.), you can jump straight to it (a.k.a. deep-linking). This isn't implemented on Windows Phone 7 (at least not from other apps, but it's really how the back button, etc. work), but the model comes straight from Silverlight on the desktop (the Navigation framework is in the Silverlight SDK), and you can see where they might take it on Windows Phone in the future.
Again, the power of the URI is its universality -- it is a common way to identify a resource. Without it, you're stuck with a tight coupling of anything that wants to navigate into your application and the application itself.

Silverlight/WP7 navigation service is fairly lacking in many regards, but there are a fair number of frameworks around that allow you to navigate to the ViewModel/View. Some examples:
Windows Phone MVP
Columbus
Xamling Core

In Caliburn Micro (MVVM framework) you have a nice way of handling navigation using only ViewModels - "Screens, Conductors and Composition"

Also keep in mind that using frames you can use routing in Silverlight to map one or more user-friendly URLs to the same .xaml file. If you would specify only the view class then Silverlight wouldn't know to which URL to map to.
Passing query parameters for state managment might be ugly, but it allows your application to be stateless which has some advantages (e.g. deep links) and fits the stateless nature of http web applications.

Related

Cucumber.js testing without relying any web browsers(Headless or real web browsers)

I was a .net based windows application developer and being a web developer now.
For the last couple of years, I tried to follow principles of Specification by example in a project.
On the last project I was involved, our team used WPF with MVVM(Model-View-ViewModel) pattern and I tried SpecFlow for testing. (Well.. the coverage by SpecFlow was very low though cause it was not officially adopted from our team and I couldn't spend enough time on it.)
Now our team started to migrate the existing windows application to a web based application and decided to use cucumber.js as a tool for implementing 'Specification by example'.
When I was trying SpecFlow before, I made all the step definitions to test ViewModel layer instead of View and it was the only way actually. What I'm confused with cucumber.js is that most of examples demonstrate how to test features via web browsers(headless or real ones).
If the features are specifying specific ui behaviors then accessing a DOM element and evaluating its value make sense. However, as far as I learned about Specification by examples, testing under the UI layer is recommended instead of UI elements directly.
It seems like most of modern web applications have layers such as MVC, MVVM(knouckout.js) nowadays. Our web application will use Angularjs and this is my theory.
I guess it is possible to use feature files - which do not state any specific UI controls and behaviors - to test under the skin of UI layer, without relying browser support. That layer would be Model of angularjs, not ui elements.
Is this approach missing something or wrong with cucumber.js?
Please give me some insights and correct me if I'm wrong.
Thanks in advance!
Specification by example specifies requirements by giving examples from the point of view of the user. What's more representative of the user: clicking items on a web page, or directly calling code? A user won't be calling methods on your view model, so in my opinion a feature test is a much better way to test expected behaviour.

Silverlight MVVM framework with navigation

We're just starting up a new (our first) Silverlight project where we want to make a back office silverlight application using MVVM. Our application will need navigation through some kind of menu UI.
I've been poking around the web finding various frameworks (Galasoft MVVM Light Toolkit / Silverlight.FX / Prism) to help with building a MVVM application but i find it hard to single out which one suits our needs the best.
Does anyone have any experience/tips on which one to pick for a larger application with many Views and navigation between them.
Also, is a navigation Application the best way to get a "framed" application (with navigation inside the frame) or is there a better way?
I'll throw in a vote for Prism/Composite Application Guidance...mainly because I've used it in a number of "for work" projects.
The modularity stuff is great - you basically code up individual projects as if they were miniature applications in their own right, and you rely on the region management paradigm to composite your multiple "modules" into one cohesive app.
It does get a bit annoying as the module count gets high, although you don't have to make each module its own project...
Take a look at this article written by Jeremy Likness. He is using Prism and Navigation framework and its a good article to get you going with. Its also not hard to take the sample he provides and apply some MVVM principles to it.

using WPF navigation in standalone applications

Is using WPF navigation in standalone applications is best practice? And can it be used with WPF MVVM pattern?
To answer your second question, yes, WPF navigation can be used quite successfully with the MVVM pattern.
As far as the first question goes, the best answer is 'it depends'. Specifically, it depends on the application you are trying to create; some applications are logically 'navigation' applications, where the users are expected to navigate through a series of screens in some fashion, while other applications have different paradigms. The best advice I can give you is not to fight it - if your application makes sense in a navigation context, then by all means use WPF navigation, but if it doesn't then do not try to shoehorn it into one.
Perhaps the best way to determine whether or not your application uses a navigation paradigm is whether or not a back button makes sense; if it does, then you'll want to use Frame or NavigationWindow so that you can use the built-in WPF navigation support.
I don't think that System.Windows.Navigation is ready for production applications yet. I've found that using it in a WPF4 application is a frustrating experience if you need to pass data between pages.
I also encountered a serious bug that causes databinding to fail after using back or forward navigation.
Numerous WPF toolkits and frameworks exist for MVVM, MVC and MVP style applications. Virtually all of them replace the Hyperlink, Page, Frame and Journal classes that Microsoft provides with custom-built navigation services. So the developer community appears to have given System.Windows.Navigation a "vote of no confidence".
Hopefully support for navigation-style apps will improve in the future.
If you have an application that's suited to the navigation metaphor, it's probably worth investigating these alternative frameworks. (Of course, these toolkits have their own learning curve associated with them.)
I'm still searching for a good approach to this problem myself.

UC(User component) concept in Win32/.NET Win forms

Couple of year ago I when to work for company as web developer. It has my first Sirius web development job, (ASPx/C#) so it has very exciting and I learned a lot about that world, from the developer point of view.
In that group we had a concept for the pages where loaded in the page UC’s (User controls), I don’t know if it’s the same in every web development team with every language, I’ll assume it is so.
The contract ended and I came back to develop win32 “winForm” application.
But since them I have tried to apply the same principle for my win32 development I learn there, meaning having bunch of UC’s (Visual User controls) that I load in the form.
They are regular visual components, not loaded in the toolbox, code is available in the project, but the component is not developed in the form, they are loaded there.
I would like to know opinions about this approach, what other are doing similar or better to this And improvements that can help us to speed up development and increase code reuse, because that is what this is all about.
If you're using the layout components in Winforms, this might be an acceptable approach although I think the thing that distinguishes the web and Windows Forms (note: NOT WPF!) is that in the former you do a lot of "compositing" which is why the UserControl concept is so useful whereas in the latter you operate on very sophisticated controls (e.g. 3rd party - in my last gig we used an incredible grid control via a small company called Infralution)
The main problem I would see is with layouts since the rendering model is a little different than the web. I know nothing about your application but if it "works" that is what is most important. I assume in this case you use things like the FlowLayoutPanel and the TableLayoutPanel properly.
If you want to go a more canonical route, take a look beyond simply creating components at how you can use the inheritance model to composite your application in a more robust way - having a base Form class that has containers for where your "UserControl" type components go and then using some kind of interface based dependency injection to swap them out while the application is running.
Finally, take a look at some of the open source Windows Forms applications out there to see if you're being too hard on yourself since common UI and reusable components are a goal in every application. Even though I've always thought Microsoft's Patterns & Practices stuff teetered towards being bloated, there are some good ideas and you should study some of the approaches of the Composite UI Application Block they put out.
Okay, not finally, there's one more thing I'd like to add: take a long hard look at WPF which will bring back a lot of the concepts from your web development days and give you that kind of power in a desktop application.

Silverlight Form Design for the Enterprise

I’m currently involved in the design of a prototype Silverlight 3 application used by call centre operators in an enterprise who take queries via phone and email. The intention of the prototype is to demonstrate how Silverlight can be used to improve the UX and overcome some of the hurdles of using ASP.NET webforms in a high latency environment. I won’t go into the details of the environment or the rationale of Silverlight 3 vs 2 or WPF, this question is about usability;
I’m looking for examples of good user interface design suitable for the above requirement that highlight some of the benefits of Silverlight. It’s a prototype so it can be a bit sexier than your usual enterprise app and have a few more bells and whistles than you’d usually get from user requirements. The goal is to both provide something functional and introduce the “wow” factor. Appreciate any resources or examples you can think of.
You've got a stateful client - one of the interesting things to do is leverage that state.
For example:
Task centric UI with multiple active tasks.
Each task represents a process/workflow that has begun, but not yet completed. Especially useful in scenarios where ther are interrupts.
Auto-save drafts to local isolated storage in case the app restarts, browser closes etc. Any partially filled forms can be restored when the app is re-launched.
The other thing is context... or preserving context of the task at hand. For example, if you want to do a lookup, you can popup a dialog, rather than navigate away from the current page.
Just some quick ideas...
Have you seen http://quince.infragistics.com? Although not specific to Silverlight it's full of proven UI methods - not Infragistics specific!
I find it very useful when designing forms and controls, maybe you will find some good suggestions there.
I like the way it encourages (forces) all your service calls to be asynchronous. From the UX point of view it means that your form is not locked up while performing a potentially laggy operation.
Animations are nice too. While they're often considered useless fluff, they can reduce the amount of surprise the user experiences when something suddenly changes. They can also be used to draw attention in a more subtle way that a messagebox in the face.

Resources