This is pretty easy.  Basically you can send any property values to the Window object that is being created to hold your root view.  Simply create a Dictionary<string, object> with the property name as the key.  Pass that dictionary to the DisplayRootViewFor<>() method and viola!

I have an application that uses the WPF frame for navigation.  The frame markup looks like this:

This Frame tag is located in my ShellView.xaml file and this takes the place of a ContentPlaceholder.  In order to navigate to another page I simply call ActivateItem( viewModelInstance ) from my ShellViewModel.  Because the ShellViewModel orchestrates the page loads I created a simple ChangeViewMessage class to throw via the EventAggregator.  My ShellViewModel handles this message and passes the viewModel instance to the ActivateItem method.  Caliburn Micro takes care of everything else.

Here is an example of the ShellViewModel loading my initial page/view in the constructor.

You can see that my first view (SelectServersView via the ViewModel) is loaded there.

In order to make Caliburn Micro work you have to patch one method to be ‘Frame Aware’.

In the View.cs class of the Caliburn Micro source in the Caliburn.Micro.WPF project change the SetContentPropertyCore method to look like the one below.  This allows you to use a Frame.

 

 

 

My first impression so far has been "Oh my Metro".  I am not sure if I like it yet.

image

The menus are in all CAPS.  WHY IS THE IDE YELLING AT ME?

image

The color scheme is a bit washed out.  I am still trying to get used to this but it does telegraph to the code and designer as they are where your eyes go.  I could get in to this high contrast look if it were to splash color at the portion of the UI I were currently using.

WPF Control / Element selection works well and very fast.

image

The UI is very responsive.  If you remember Visual Studio 2008 (Ugh I still have to work in VS2008) clicking on a UI element in the designer renders properties in about a minute if you are lucky (and have ReSharper disabled).  Visual Studio 2012’s new IDE is very responsive.  Thank you!

image

Visual Studio 2012 adds List as an option for your DataSources if you are a drag and drop binding kinda guy.

image

The XAML Designer has some Blend functionality built right in now.  From the left: Zoom Level, Toggle Effects, Show Snap Grid,  Snap to Grid Lines, Snap to Snaplines, Show Annotations.

Toggle Effects

This allows you to turn off the special effects bound to controls.  This helps speed up the designer a great deal.

Annotations

Allows you to view annotations about your WPF application (presumably from a sketchflow annotation).

image

The Solution Explorer looks Metrofied and adds a really useful Collapse All command and a Pending Changes filter command.

I am working on a project where I need to resize a bunch of raster images from miscellaneous sizes to fit within a certain frame.  More specifically, I need a bunch of icons for an iPhone application and I need them to fit within a 64px by 64px frame.  I found a bunch of Photo Shop scripts, some console apps, and a few spamware solutions.  I figured half an hour and I would have one that works well.  I was right.

image

So here is how the app works:

Drag and drop the graphics files you wish to resize into the application.  The files will show in the list view area.  Next, enter the Max Height and Max Width values and then click the Resize button.

The application will write the resized file next to your original with _MaxHeightxMaxWidth appended to the filename.  Original files are not modified in any way during this process. 

So if you found this blog post in hopes that you would find a quick and simple image resizer for free, here is the link to the binaries: 

A little about the application source code.  The application is a .NET 4.0 WPF application that follows the M-V-VM (MVVM) design pattern.  Since there is drag and drop support in the application there is a little code behind to support this.  The rest of the application follow the MVVM pattern.

There is a tiny image resizer class in the project that you are free to use.  This is located in the DevSQL.Imaging assembly. 

The source code can be found below.

Here is the snippet I am currently using to implement a basic DelegateCommand class.

CODE:

Snippet file:

Business Problem

Large companies have lots of facilities which need spare part inventory on hand.  Facility operators may not reorder parts in a timely fashion which can lead to a local shortage of equipment.  Some facilities may hoard equipment creating a local surplus of equipment.  Both extremes are costly to a company.

Solution

Provide a simple to use touch screen computer that detects when a part is leaving or entering the spare parts room.  Upon detection of the part the touch screen computer displays a ‘tag’ with information about the part.  The facility user can touch the tag on the screen and note the use of the part.  When parts come in for replenishment the facility user can notate the put away location of the part.  When are part is used inventory levels at MDSi are updated.  If the minimum stocking level is reached a reorder is automatically generated and shipped to the facility to keep the stocking level true.

Components

RFID Client (Touch screen workstation)
This is the device with which the facility users interact.

image

The client is built with Microsoft .NET Framework 4.0 and uses Windows Presentation Foundation (WPF) to present the UX.  The client leverages the Model-View-ViewModel (MVVM) architectural pattern and is written in C#.  Communication to the home office is provided via WCF services.

image

RFID Tags are read via a Motorola XR-450 tag reader.  This reader was selected because it has a built in Windows CE operating system that allows us to write Mobile Embedded .NET applications to interact with the reader and with our WCF Services.  The RFID Client Workstation has a Windows Service written in C# and .NET 4.0 which continually polls the XR-450 reader for new tags.  The service exposes a .NET Remoting service which is consumed locally by the client UI.  Multicast events are thrown and the client system can respond to new tags accordingly.

RFID WCF Services
All RFID Clients communicate to a set of centralized web servers in an NLB farm.  The WCF Services provide a data exchange layer which provides caching by leveraging the AppFabric Cache feature of Windows Server 2008 R2.  Data is stored in a SQL 2008 R2 Cluster and the data is organized through Microsoft Dynamics AX 2009.  X++ and Business Connector code was created to interface through the ERP system and pass through all of the business rules configured in the Dyanmics Ax system.  In addition to using the .NET Business Connector and custom Dynamics Ax projects to manage the data, ADO.NET, Linq and C# is used in the creation of these services.

RFID Management Display
A Network Operation Center (NOC) application was created to provide real-time node (RFID Touch Screen Client) availability data.  This data is organized on a map and allows an operator to drill in to a workstation and remotely manage the system.

image

RFID Warehouse Printing
Tools were created to interface with the Microsoft Dynamics Ax 2009 ERP system which allow a warehouse employee to print RFID labels for items being shipped out for replenishment.  This system interfaces with the Zebra RZ 400 RFID Printer.  This application was created using WPF, WCF, MVVM.

image

RFID On-Site Inventory and Auditing Tool
This application allows a warehouse specialist to audit a sparing facility.  This application is written using WPF and .NET 4.0.  The application consumes the same WCF services provided for the RFID Client to connect to the ERP system.  The application allows a specialist to print labels via a wireless Zebra RP4T RFID Label printer.  Using this application a project coordinator can determine what inventory is needed on site and what can be returned for general usage to the Distribution Center (DC).  This allows for a quick and efficient auditing process.  The warehouse specialist does not need to know anything about the product, just scan the serial number and the application tells the specialist the disposition of the part based on the Min/Max settings in the ERP system.

image

RFID Node Creation Tool
The Node Creation Tool allows a support engineer to provision a remote RFID Touch Screen Client from a central location.  A support engineer can provision all of the standard configuration settings for Development, Test, and Production from the single tool.  This application was created with WPF, C#, WCF, MVVM.

image

RFID Online Spares Management Web Application
A Silverlight application was created to provide scaled down functionality for locations that do not have the RFID Touch Screen client installed.  Some locations need the ability to consume, count and audit their inventory without an RFID client.  In this case a laser barcode scanner is used to scan the RFID barcode.  This application was written in Silverlight 4.0, uses WCF Services, and employs the MVVM architectural pattern.

image

So Web Application projects have this great new feature that allows you to use an XML Transform file to merge settings into your Web.Config file based on the build configuration.  For example, if you have a Release build configuration you might want your connectionString section to point to a production server instead of your development server.  See this link for more information on Web Config Transforms.

This is a really cool feature and it is possible to use this with non-web application projects.  You can configure your project file to support this very easily.  You do need to insert some XML into your csproj file but it is really lightweight.

First, Add an App.config file to your project if you do not already have one.

Next, close Visual Studio and open your *.csproj file in notepad.

Go to the very end of the file and insert the UsingTask and Target sections directly above the </Project> closing tag. 

 

Now find the section that has your App.config file include.  It will likely be in a <None /> tag.  Replace that tag with the following code. (Include a App.CONFIGURATION.config file for each build configuration you use.

Save your csproj file and open it up in Visual Studio again.

image

Now when you build your solution/project the XML Transforms in your App.CONFIGURATION.config file will be merged at build time.

I had to build a small configuration screen for an over-the-internet printing solution for Microsoft Dynamics Ax.  The application has an image that I want the user to click with either the left or right mouse button to open the context menu.  This menu allows the user to start or stop the print engine service.

image

Left or right clicking opens the context menu.

image

Here is the XAML for the Image with Context Menu.

Note: MVVM Commanding is not used here for simplicity of this post.

In this XAML snippet I named the Image and consumed the MouseLeftButtonUp event on the Image.  I also added the context menu to the Image control and named the ContextMenu.

The code behind looks like this:

In this code, PlacementTarget indicates the UIElement that the context menu will pop out from.  In this case we just use the Image element itself as passed in to the event handler via the sender argument.

Next, you simply set IsOpen to true and the context menu will be displayed over the PlacementTarget.

I use these two snippets a lot for WPF and Silverlight development.  I decided to post them on the blog so that I have them available to me whenever and wherever.  I always seem to be searching through older projects for this code.

vmb

This snippet creates the ViewModelBase that I use almost everywhere.  It simply implements INotifyPropertyChanged and works in both WPF and Silverlight.  I use this for my ViewModels so that the properties on the VM are observable for databinding.  I use this in conjunction with my propsn snippet that creates a property with SafeNotify calls in the setter.

mb

This snippet is used to create the ModelBase.  Again, this is a WPF / Silverlight compatible class.  I link my model such that it compiles for WPF and Silverlight so that I can share my model between my WCF and my UI.  This class gives me INotifyPropertyChanged, SafeNotify, and a ToString implementation that uses reflection to dump a shallow representation of the class.

Hope this code helps someone.