Portland Silverlight User Group 10 Aug 2010

July 25, 2010

On 10 Aug 2010, Adam Kinney and I will be presenting at the Portland Silverlight User Group.

As you know I work on the WPF & Silverlight Designer in Visual Studio as part of the Expression Team.

This session will provide guidance for writing applications that are toolable.  Many folks use the term, Blendable.

Do you use MEF, IoC or Service Locator to resolve dependencies?  Do you use M-V-VM or code-behind click handlers? Do you use sample data?  No problem. 

We’ll show you how to have a successful design-time experience with the Visual Studio and Expression Blend tools.

Session Abstract

Building toolable Silverlight applications that enable the designer developer workflow

Warning: We won’t be 20 seconds into this session before mashing the gas pedal to the floor. After looking at the XAML tools Blend & Cider, we’ll dive deep into toolable application design.

Toolable applications not only enhance the initial development experience but also provide benefits to long term application maintenance.

An additional benefit is the enabling of the designer developer workflow. See the two roles played out in the presentation as they collaborate without clobbering each other.

BlueCiderLogo_4

Wanting to properly represent the WPF & Silverlight Designer, I’ll be sporting a nice XAML blue do. 

Just look for the guy with a red Hawaiian shirt with blue hair.

See you in Portland!

Just a grain of sand on the worlds beaches.


Portland .NET User Group 3 Aug 2010 + Mole 2010

July 16, 2010

I’m very excited to announce that I’ll be speaking at the Portland .NET User Group on 3 Aug 2010.  This will be my first time visiting Portland and I’m looking forward to it!  This wide open night will close out with the first time unveiling of Mole 2010.

Line of Business for WPF

Departing from the normal speaker driven model, the audience will drive the WPF LOB presentation by selecting topics from the following SpeakerMenu at presentation-time:

<Window
    x:Class="Portland.PADNUG"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="3 Aug 2010 – Portland .NET User Group" Height="Stratosphere" Width="Horizon">
    <Grid>
        <SpeakerMenu Speed="WideOpen">
            <MenuItem Topic="Validation" />
            <MenuItem Topic="Toolable Application Design" />
            <MenuItem Topic="Decoupled Messaging" />
            <MenuItem Topic="Behaviors" />
            <MenuItem Topic="Displaying Dialogs from the ViewModel" />
            <MenuItem Topic="Setting VisualState from the ViewModel" />
            <MenuItem Topic="Resolving Dependencies in a ViewModel" />
            <MenuItem Topic="Reporting UI Exceptions to the ViewModel" />
            <MenuItem Topic="Logging & Exceptions" />
        </SpeakerMenu>
    </Grid>
</Window>

Mole 2010

To close out the evening, I will unlock the vault and unveil for the first time, Mole 2010 for Visual Studio 2010. No one outside Team Mole has seen or heard of any new features we have developed.

Portland, hold on tight because Mole 2010 is rolling into town!

Mole 2010 will be available in August 2010.

Close

Very much looking forward to meeting developers that I have been emailing and Tweeting.

Have a great day,

Just a grain of sand on the worlds beaches.


Non-Linear Navigation in Silverlight 4

July 7, 2010

In the last Seattle Silverlight User Group meeting I spoke about Non-Linear Navigation in Silverlight. 

This blog post is a proof-of-concept for Non-Linear Navigation in Silverlight 4 Navigation Applications.  When I was first exploring this, I did not use the Navigation Application template, instead I implemented Non-Linear Navigation similar to what I did in BBQ Shack.  Several friends asked me to try and use the Navigation Application template so I did.

The code in this post builds on any of the Navigation Application templates.  For this post, I’m using the default template, but there are other cooler ones in the Visual Studio Code Gallery.

What is Non-Linear Navigation?

I first heard about Non-Linear Navigation in this dnrTV video that Billy Hollis did.  While on a cruise to Alaska I wrote the BBQ Shack application, which is a WPF implementation of Non-Linear Navigation.

Non-Linear Navigation is one way for Silverlight line of business applications to provide users with a desktop application like experience.  This would include both in-browser and out-of-browser applications.

The primary problem that is being addressed in this blog post is how to allow users to easily switch between unfinished tasks and for them to visually see what tasks they started but then navigated away from.

For example, the user is adding a new item to the system.  Their boss calls them to look up history of another item.  The user does not want to quit the add new item task to look up history of another item.  In your current Silverlight applications, how would you handle this scenario?

Non-Linear Navigation easily enables this scenario, by allowing the user to navigate away from the task and start a new task.  The original task is moved off screen but not destroyed and the task information is made visible on the UI.

In the below image, the user was working on an Inventory task, then switched to another task; in this case the About page.  Notice the UI has clearly indicated to the user that they have one active Inventory task.

about

In the below image the user has just clicked the Inventory button at the top right and navigated to the Inventory module home page.  Notice the three visual clues presented to the user.

  • Top right – Inventory- (1) number is the total number of Inventory tasks open
  • Left side – Item – (1) number is the total number of Item tasks open
  • Right side – the active item is displayed in a list with a link to return to the task

inventory

The information surfaced about open tasks on the UI comes from a collection.  This makes it very easy to have any sort of UI your designer/deviner/developer can dream up.

How is this Implemented?

When you want to provide custom page loading in a Navigation template you’ll want to implement a Frame.ContentLoader.

David Poll is the grand master of Silverlight Navigation template and custom ContentLoaders.  David is the Silverlight Program Manager for Navigation and has written a lot about navigation.  You can read all of David’s Navigation posts here

David and I met several times to discuss navigation and the problem space I was exploring.  He provided me super guidance on navigation in Silverlight which I appreciate very much.  Thank you David!

The below XAML is familiar to Silverlight developers who have used one of the Navigation templates.

When the Frame receives a request to Navigate, it passes the heavy lifting off to the ContentLoader.

The default Navigation template does not specify a ContentLoader.  If a ContentLoader is not specified, the default ContentLoader will be used.  In the below XAML you can see where I have added the NonLinearNavigationContentLoader.

ContentLoaders are super cool in that you can chain them.  The commented out below XAML shows how to chain ContentLoaders.  The chaining of ContentLoaders allow each ContentLoader to perform an action, conclude the processing of the Navigate request or defer further processing to the next ContentLoader.

David Poll has written a lot about chaining ContentLoaders so I won’t attempt to duplicate his work in this space.

<navigation:Frame
    x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}"
    Source="/HomeView" Navigated="ContentFrame_Navigated"
    NavigationFailed="ContentFrame_NavigationFailed">
    <navigation:Frame.ContentLoader>
        <!--This is where our custom Content load is added-->
        <navigatus_Navigation:NonLinearNavigationContentLoader>
            <!--

            <navigatus_Navigation:NonLinearNavigationContentLoader.ContentLoader>
                <local:YouCanChainAnotherContentLoaderHere />
            </navigatus_Navigation:NonLinearNavigationContentLoader.ContentLoader>
            -->
        </navigatus_Navigation:NonLinearNavigationContentLoader>
    </navigation:Frame.ContentLoader>
</navigation:Frame>

Simply stated, the NonLinearNavigation ContentLoader does the following when the Frame receives a Navigate request:

  • Checks if the requested Uri is in the collection of active tasks
  • If not in the collection it will:
    • Defers loading to the default ContentLoader (or chained ContentLoader)
    • After content is loaded, it attaches a NavigateKey to the NonLinearNavigationContentLoader.NavigateKey attached property.
  • If in the collection it will:
    • Return the object matching the Uri to the Frame, no further processing is performed.

Kind of simple, uh?

For the MVVM folks out there, you’ll be happy that a Navigation can easily notify your ViewModel when the View is being brought into view or when its being navigated away from.

The PageBase class does implements this automatically for you.  In some cases a Page may want to override the behavior.

The ViewModelBase class handles some plumbing that deriving classes can override to provide context specific actions.

In the below code snippet from the ItemMaintenanceViewModel class, we can see two overridden methods.

OnNavigatedTo either instantiates a new record or calls the business layer to load a record.  Notice how it first checks to see if it already has data loaded.  This would be the case when navigating back to an active task.

OnNavigatingFrom fulfills two important purposes.  First notice the cancel parameter; this allows the ViewModel to opportunity to cancel a Navigation request.  Second, this method populates the attached NavigateKey with the latest form data.  There are many different techniques you could use to populate the NavigateKey, I’ve chosen the simplest method I could think of to illustrate concepts.

public override void OnNavigatedTo(Object param) {
    if (this.Item == null) {
        if (param is Int32) {
            Int32 id = (Int32)param;
            if (id == 0) {
                this.Item = new Item();
            } else {
                this.Item = InventoryBLL.GetItem(id);
                if (this.Item == null) {
                    throw new Exception(Constants.RECORD_NOT_FOUND);
                }
            }
        }
    }
}

public override void OnNavigatingFrom(ref Boolean cancel) {
    if (base.NavigateKey != null && this.Item != null) {
        if (this.Item.ItemID == 0) {
            base.NavigateKey.Mode = Constants.ADDING;
        } else {
            base.NavigateKey.Mode = Constants.EDITING;
        }
        base.NavigateKey.Key = this.Item.ItemID.ToString();
        base.NavigateKey.Title = this.Item.Description;
        base.NavigateKey.IsChainable = true;
        base.NavigateKey.ApplicationSuite = Constants.APPLICATION_INVENTORY;

        //NavigateKey.CurrentSource is set in PageBase as it requires access
        //to the Navigation Service
    }
}

Navigatus Application

I’ve broken the Navigatus Application into several assemblies to demonstrate how to have a Shell Page that hosts the application content.  The actual application content comes from satellite assemblies.

Check out the About page.  When you navigate to it, a counter will start incrementing.  After a bit, navigate back to it, you’ll see that the counter continued to work even though the page was out of view.

The techniques discussed here open up many possibilities for Silverlight 4 line of business applications.

Download

Navigatus C# Source Code

I’ve been programming in C# since August of 2009.  Most of my work from here forward will be done in C#.  For my VB.NET brothers in arms, Karl has moved on to the dark side.  Feel free to send me an email or comment if I need to clear up some C# code.  Except for { } or ; it’s pretty much the same.

I’ve move to C so that I can pickup Objective-C and C++.

Close

I hope you can learn something from this proof-of-concept application.

I was hoping to have more time to work on a nice Silverlight line of business application but my non-work time is currently being consumed by my work on Mole 2010 and learning Windows Phone 7.  In my spare time I’m reading my first C++ book.  Once Mole 2010 ships, I need to finish Crank (my super cool code generation application) and then I hope to write a cool Silverlight line of business application that uses the techniques here.

I’m also hoping the community embraces navigation and develops patterns and frameworks for enabling RAD applications that empower uses of the software we write.

Have a great day,

Just a grain of sand on the worlds beaches.


XAML Power Toys for Visual Studio 2010 for Cider version 2.1 Silverlight 4 Support

July 7, 2010

I have just updated XAML Power Toys for Visual Studio 2010 for Cider to version 2.1 adding support for Silverlight 4.

Please Note

I have two XAML Power Toys products on my blog.  They are not the same.  Get both, you’ll be glad you did. 

The first one is for working in the XAML Editor and to create ViewModel’s. 

The second one works with the Cider Designer.  This is post is about this product.

New Features and Fixes

  • Added support for Silverlight 4
  • Fixed installer for x64 systems.  Added workaround for Visual Studio 2010 issue with loading custom control designers for Silverlight 4

Download

You can get the new version on the XAML Power Toys for Cider Home Page.

Have a great day,

Just a grain of sand on the worlds beaches.


XAML Power Toys for Visual Studio 2010 version 6.1 Silverlight 4 Support

July 7, 2010

I have just updated XAML Power Toys for Visual Studio 2010 to version 6.1 adding support for Silverlight 4.

New Features and Fixes

  • Added support for Silverlight 4
  • Corrected ViewModel creator spit
    • If you remove the CommandParameter type in the Command Creation Window, the spit will no longer add the CommandParameter type to the RelayCommand or DelegateCommand, to the methods or lambda’s.
    • If you specify a CommandParameter type in the Command Creation Window, the spit will add the CommandParameter type to the RelayCommand<T> or DelegateCommand<T>, to the methods and lambda’s.
  • Fixed the property discovery of model objects to add all public properties of all base types.

Upgrading

If you are upgrading from the previous version, PLEASE visit the Set Controls Defaults page and update this page for Silverlight 4.

You’ll want to change your Silverlight alias’s to “sdk” instead of “data” or “controls” as this is what Visual Studio 2010 with Silverlight 4 now uses.

When you drag a Label, DataGrid or DatePicker control from the Toolbox to the Silverlight 4 design surface, Visual Studio 2010 now uses “sdk” for the xamlns alias, so by changing your default you’ll be in sync with Visual Studio.  If you are a new user, “sdk” is defaulted for you.

You should also set the TargetNullValue option for both the Silverlight and WPF TextBox.

You should also set the Silverlight Textbox Validates On Data Errors, this is new to Silverlight 4.

Download

You can get the new version on the XAML Power Toys Home Page.

I was unable to establish a CodePlex project tonight because the source code server was off-line.

For now, the only download available is from my SkyDrive.  I’ll try and set XAML Power Toys for Visual Studio 2010 up on CodePlex this week.

Have a great day,

Just a grain of sand on the worlds beaches.


Follow

Get every new post delivered to your Inbox.

Join 136 other followers