24 Feb 2012

Charting with Lightswitch

One of the key business aspects not included with Lightswitch 2011 is a great set of charting controls and often I need to have a few for the projects I am working on. Thankfully with the Silverlight Toolkit and a touch of code I can have BRILLIANT charts for no extra costs!

Below are three charts using the Silverlight Toolkit in Lightswitch, which I think look FANTASTIC and it is fairly easy to do in four easy to follow stages.

imageimage image

For this tutorial I have a simple structure of engine parts, costs over time and purchases which looks a little like the image below and for I have already created the data structure and UI for adding those in Lightswitch.

image

Stage 1: Get the toolkit

To start off we need to switch out of the Logical View and into the Files View, to do this in Solution Explorer click the “Lie to me button” (that is what I call it) and change the view.

image

Next right click on the client project and select Manage Nuget Packages. If you do not have Nuget yet, stop, download Nuget from www.Nuget.org and install it and come back.

image

In Nuget search for the silverlight toolkit and install the Data Visualization package. Now unfortunately Lightswitch isn’t too good with Nuget, so really we are using this as a way to get the packages but they are not properly installed as you may expect.

image

Stage 2: Create the screen and add the control

Now switch back to the Logical view and add a new Editable Grid Screen, give it a nice name but do not select any Screen Data.

image

In your new screen, click the add button at the bottom and select New Custom Control. If you do not have that, you have selected the add option for the Screen Command Bar, so make sure the Rows Layout at the top is selected.

image

Now we need to add the assemblies for the Silverlight Toolkit packages, to do this press the Add Reference button in the Add custom control screen.

image

Browse to the packages folder in the root of the Lightswitch project and add the two assemblies. Once done browse the System.Windows.Controls.DataVisualization.Toolkit assembly and go to System.Windows.Controls.DataVisualization.Charting.Chart class and select OK.

image

Stage 3: Configure the chart control in Lightswitch

The control should now be listed. Next go to the properties and give the chart a name, this is important so name it something you will remember.

image

Now we change the sizing of the chart control to be Stretch for both Horizontal and Vertical Alignment. This allows the chart to use all the space on the screen!

image

Stage 4: Add some code to get the data and put it in the chart

Now we need to add the code to get the data and render the chart. We do this in the Created event for the screen (to get there, click the Write Code button in the toolbar and select the event).

image

Now we add some code to the event, which does:

  1. Find the chart control.
  2. Get the data from the DataWorkspace into a list.
  3. Set chart to use the data.
partial void CostOverTimeChart_Created()
{
    // Write your code here.
    var chart = this.FindControl("chart");
    chart.ControlAvailable += (s, e) =>
    {
        this.Details.Dispatcher.BeginInvoke(() =>
        {
            var dataPoints = (from Costs c in this.DataWorkspace.ApplicationData.CostsSet
                              group c by c.EnginePart).ToList();

            var chartControl = e.Control as Chart;
            chartControl.Dispatcher.BeginInvoke(() =>
            {
                chartControl.Series.Clear();
                foreach (var group in dataPoints)
                {
                    chartControl.Series.Add(new LineSeries()
                    {

                        Title = group.Key,
                        IndependentValuePath = "PointInTime",
                        DependentValuePath = "Cost",
                        ItemsSource = group
                    });
                }
            });
        });
    };
}

If we dive into the code:

  • Line 4: We use the FindControl method with the magic string we named the chart to find the control that wraps the chart.
  • Line 5: We attach to the event for when the chart is available.
  • Line 7: We use the dispatcher for the screen to run a call to the DataWorkspace to get the data and put it into a list. We need to dispatch this as the DataWorkspace is in a separate thread.
  • Line 12: We get the actual chart control now from the event arguments.
  • Line 13: To set the values on the control we use the charts dispatcher as it is separately threaded.
  • Line 15: We clear any existing  series and then add new series. This code is nothing special to Lightswitch, this is just normal Silverlight charting.
  • Wrap up

    It seems like a lot to do this, and it is. You could make this easier by wrapping this in a custom Lightswitch control which would give you GREAT reuse, but that is a lot of work too. In the long run if you use lots of charts you will save time by building the custom control – but if you need just one or two this is a little quicker and less learning.

    Below you will find a link to the sample product I used to create all the charts and it has all the code in it too, if you are looking for it. Make sure you have Nuget installed before you use it!

    AttachmentSize
    DemoLS.zip1.97 MB
    24 Feb 2012

    VS/TFS 11 Announcement Crib Notes

    1680.SolutionExplorer-2The last few hours have been a buzz of excitement for .NET developers as the covers have been lifted for the next releases of TFS, VS & .NET 4.5 – however there is a problem. There is SO much info wrapped in nice marketing & business talk you will spend hours trying to get through it all, so here are the crib notes. Following each note is a number in braces, this is the number of the source so you can go to it for more info if you wish:

    • .NET 4.5, VS 11 & TFS 11 beta’s will be available on the 29th Feb. [1]
    • You can use the products in production from beta (technically called a go-live licence) [2]
    • Visual Studio 11 has had a UI polish, similar layout but less toolbars by default, less colours (icons are monotone) & a touch of Metro like thinking (white space & typography) [2]
    • Five editions (or SKUs) of Visual Studio will ship: Express, Test Pro, Pro, Premium & Ultimate. Same as we have in 2010. [3]
    • TFS will have at least two editions, Express (think TFS basic but FREE) and another edition. We may have more than that. [8]
    • Visual Studio Professional and up will include Lightswitch! [3]
    • The architecture tool diagrams can now be read in professional & premium versions too (in 2010 it was premium only). Creation still requires ultimate. [4]
    • IntelliTrace is supported in production (still an ultimate only feature). [4]
    • Windows Phone 7 tools included with professional and higher editions of Visual Studio 11. [4]
    • Express will have two versions: Windows (WPF, WinRT, etc..) & Web (ASP.NET, MVC etc…). [5]
    • There are two themes for Visual Studio: Light (pictured above) & Dark which feels like a Expression Blend style. [6]
    • Quick launch is a new search feature allows you to search for any command or option in Visual Studio. [6]
    • Search has been added to most used tool windows, like solution explorer. [6]
    • ASP.NET MVC 4 has a bunch of evolutionary improvements, nothing to wet your pants on IMHO. [7]
    • ASP.NET Web API is a big new feature for both MVC & WebForms for building API’s for the web. Think services like WCF but built for the modern web. [9]
    • Visual Studio 11 is a code name – expect a name change by release. [10]
    • Workflow hubs in Visual Studio 11 allows you to focus on a task in a single place, rather than have to move around multiple windows. [11]
    • Preview tabs allow you to sneak a peek at documents without needing to actually open them. [10]
    • C# 5 (yes, it is version 5 of C# that is shipping with .NET 4.5 – who says this is confusing) has support for async. [10]
    • New code compare tool & UI that doesn’t suck. [11]
    • New code review tool support in TFS & Visual Studio. [12]
    • New mock up design tool that ships with Visual Studio/TFS that allows you to build mock user interfaces in Powerpoint. Think Sketchflow without the code or Balsamiq. [13]
    • New Visual Studio METRO’d logo [14]: VS11-Beta_h_c

    Want to see some pictures of all of this? http://www.microsoft.com/presspass/presskits/developer/imagegallery.aspx

     

    Sources

    1. http://blogs.msdn.com/b/somasegar/archive/2012/02/23/the-road-to-visual-studio-11-beta-and-net-4-5-beta.aspx
    2. http://blogs.msdn.com/b/jasonz/archive/2012/02/23/sneak-preview-of-visual-studio-11-and-net-framework-4-5-beta.aspx
    3. http://www.microsoft.com/visualstudio/en-us/products/beta-products
    4. http://www.microsoft.com/visualstudio/en-us/products/features-chart
    5. http://www.microsoft.com/visualstudio/en-us/products/beta-express
    6. http://blogs.msdn.com/b/visualstudio/
    7. http://weblogs.asp.net/scottgu/archive/2012/02/19/asp-net-mvc-4-beta.aspx
    8. http://blogs.msdn.com/b/bharry/archive/2012/02/23/coming-soon-tfs-express.aspx
    9. http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx
    10. http://www.microsoft.com/presspass/features/2012/feb12/02-23VisualStudioBetaPreview.mspx
    11. http://www.microsoft.com/presspass/ImageGallery/ImageDetails.mspx?id=2c8135ad-fefd-48c2-888f-83b6987a4e87
    12. http://www.microsoft.com/presspass/ImageGallery/ImageDetails.mspx?id=2a0b1cf8-9d74-4603-a2d1-03d8ef989a8c
    13. http://www.microsoft.com/presspass/ImageGallery/ImageDetails.mspx?id=240cbb53-9dd5-4262-b0cc-cdb9a57485d3
    14. http://www.microsoft.com/presspass/imagegallery/images/products/developer/vs/logo_vs11beta_print.jpg
    13 Feb 2012

    Silverlight - When does it REALLY end?

    imageWhen you ask Microsoft, “Microsoft WTF is going on with Silverlight 5? Is it the last version of Silverlight? Will you support more versions?”, you get given a link to the Silverlight Product Support Lifecycle Page (this has happened more than once to me). This page lists when Microsoft will support Silverlight until, and you will see that for releases 1 through 4 it was between two & three years. For Silverlight 5 it is a DECADE. This implies that this release will be with us for some time, so it is a good bet that it will be the last one. Before I continue this post is about Silverlight on the desktop not Silverlight on the phone which is a different thing all together, I have very different views to Silverlight on the phone.

    So what does that REALLY mean to us? Mainstream support will end in 2021. Does that mean browsers will work & Visual Studio will work? Maybe is the real answer. Mainstream support (as defined on the Microsoft website) means

    • You can contact Microsoft and ask for help. You may get this for free or pay for it. I’ve used this in the past and gotten hotfixes and general installation help on other products. It is GREAT!
    • Security patches.
    • The ability to request non-security hotfixes (i.e. you find a bug, you log it with support, you wait a while, you get a fix).

    It does not mean tools or browsers will support it! Both are listed on the Silverlight page so they have given us this info too. Tooling is promised for a minimum of 12 months after release which means that Visual Studio & Blend releases 12 months following the release of Silverlight 5 will support it. This means we can expect Visual Studio 11 and Blend 5 to support it. However there is NO promise for further tooling updates, which means that VS 11 & Blend 5 are likely the last releases to support Silverlight. Visual Studio has a trend of 5 years support so expect bugs in tooling to no longer be fixed after that. The other tool we must consider is Lightswitch, which is based on Silverlight. What is it’s life? It is listed as 2017! So do not expect you current Lightswitch projects to continue until then!

    In reality those are tools, we can continue to use them long after end of life (as the SQL team forces ANYONE who wants to create reports for SQL 2000 or 2005 will know). The real concern must be out customers and their interface to Silverlight, the browser. The support lifecycle page links to a page with supported browsers and has an interesting note. They will support those browsers until end of mainstream Silverlight support (2021) or until the browsers own support ends WHICH EVER IS SHORTER!  So that means if IE ends of life sooner, they get to stop supporting it sooner. So when will that really end? The latest browser on the list is IE 9, so looking that up gives us nothing – it is a component and thus it’s lifecycle is linked to it’s parent product Windows 7 which ends of life in 2015!  I am running the Windows 8 beta and I know Silverlight 5 does run on it with Internet Explorer 10, so if we assume that they follow the same lifecycle and this is the last release to support it that means we can expect browser support only until 2017!

    So the reality is that your operating system, your browser & your tools all stop supporting it in 2017 – that is the real end of life to me, and that is 5 years away! Sure you can get security hotfixes for another 4 years after that, but really what good are those when your tools, OS & browser can not be fixed. So for me the real end of life is 2017.

    Finally let be clear, there is assumptions and estimations based on previous support life cycle numbers. Microsoft could be preparing something and just not communicating it and this could all be wrong, but as Microsoft is not communicating this is all we have to go on anyway. There is another Silverlight, that one powers Windows Phone apps – I view these are two completely separate products (similar features but not the same, but different tools and different requirements) with the same name so my view here does not imply ANYTHING to Windows Phone 7 – I do believe that Silverlight will be with us for much longer.

    09 Feb 2012

    The MVP award

    WP_000575Being a MVP gets you very little, some status boost in those who misunderstand it (MVPs are not awarded for technical skill & a lot of people think MVP = expert), a MSDN subscription, a lot of paperwork (including multiple NDA’s), some access to product teams (this varies from product team to product team – some have great interactions others are poor) and a trophy.

    To the right is my MVP trophy (as well as ALM Rangers award and MVP of the year cube) and I think it looks pretty awesome but how does it get to me?

    In this post I want to take a slightly tongue in cheek look at the box the MVP award comes in and what it is saying about MVP’s.

    WP_000576WP_000577WP_000578

    Above you can see the three years of the trophy box. So lets analyse those box covers. I am assuming that the person on the box is supposed to represent MVP’s.

    • MVP’s are dress smart casual always – chinos & a blue shirt are required. Hah, not likely.
    • MVP’s have neck problems causing them to tilt their heads. This is likely true from all the time people spend at their machines.
    • MVP’s always have their laptops with them. Also likely true. Next year he better have a Windows 8 tablet though.
    • Interesting that 2010 guy got one cover while 2011 guy got to come back in 2012. Guess 2010 guy wasn’t re-awarded Winking smile
    • 2011 guy has gotten smaller in 2012 – are we shrinking away or did Mr 2011 not do enough work?
    • In 2010 and 2011 the ghosts of MVP’s past are clearly standing in support for the MVP. In 2012 they aren’t concerned anymore and just chatting with each other.

    What would I do differently? Easily, take a photo from MVP summit with real MVP’s engaging with each other and put that on the cover. What may be nice is to have new 2012 MVP’s (i.e. first timers) get together to pose for it and so there is extra incentive for 2013 – a box with real MVP’s that could include you.

    04 Jan 2012

    Presentation Dump - End 2011: Azure, Windows 8, Lightswitch, Visual Studio Tools, TFS & Roslyn

    With 2011 finally done and dusted it is time for the bi-annual presentation dump, where I upload most of the slides I have done in the last six months to share with you! I say most, as some presentations are NDA and those, unfortunately, I can’t share out – but where I can upload slides I do!

    In this presentation dump we have:

    • Windows Azure Platform Overview: This is a talk I gave at the ImagineCup to faculty members about what Microsoft Azure can offer!
    • Windows 8: A brief introduction shortly after the //Build conference to help share what information we had on Windows 8
    • Lightswitch: The latest iteration of my Lightswitch talk contains a structure overview before the demo and then goes into detail on the themes and extension model in the product.
    • Developer Productivity Tools: A session that looks at FIVE FREE tools for Visual Studio that will assist in the productivity of any Microsoft .NET developer in Visual Studio. Tools covered are fxCop, StyleCop, Pro Power Tools, CodeRush Xpress & Nuget.
    • An Introduction to TFS: The target audience for this is someone or company who is using another source control (like VSS) and is thinking about moving to TFS but isn’t sure where to start. This BRIEF introduction tries to provide a high level view that TFS is not just source control it is a LOT of more and thus has a lot more power. It also mentions migration from VSS and provides guidance for success.
    • Roslyn: This is an early look at Roslyn

    It is definitely a quieter period than most, in terms of number of unique slide shows and I think a lot of that comes out of the information black out from Microsoft prior to //Build, but it was still a very period with me presenting Lightswitch NUMEROUS times and also Tech·Ed Africa where I did four presentations!

    You can get all the slides and details by clicking “read more” below!

    Windows Azure Platform Overview

    Windows 8

    Lightswitch

    Developer Productivity Tools

    An Introduction To TFS

    Roslyn

    03 Jan 2012

    MVP for a third time :)

    mvp

    364 days ago & 829 days ago, I blogged about being awarded a MVP from Microsoft and I am proud to announce that I have been awarded a MVP for a THIRD time!

    Thank you to all that were part of making this happen, I am very honoured by all of you.

    What is an MVP? In short it is a thank you for helping Microsoft communities. The long version can be found here.

    01 Dec 2011

    Platforms > Implementations

    imageI recently read an insightful post about how being a developer is less about coding and more about tooling, and while I do not agree with all of the post, the fact we as developers are tool obsessed rings very true. This obsession with tools becomes a white hot rage when our favourite tool is threated with extinction or causes a world of panic when a competing tool is proposed without enough information on it.

    Let’s look at two key examples of that:

    • WinForms was very popular and when Microsoft brought us WPF, there was major push back from those who did not want to change and learn a new tool. If you reading this, then you are thinking well time solved that, I disagree. This very week I was asked about WinForms vs. WPF again. Time doesn’t heal all wounds, it just gives some of us time to move on.
    • To illustrate the world of panic I can use a more recent issue – Windows 8! Remember all the discussion before //Build about the death of <insert your favourite tool here>? The confusion caused by incomplete discussions around tools we love caused panic.

    So what is the solution to this? I think simply a mind set change would be enough. The mind set change needed is to remember that a platform is more important/powerful/useful than a tool. I would like to take credit for this idea, but the first time I heard anyone mention this was a few years back and it was Scott Hanselman talking on MVC almost three years ago to the day. He mentioned that ASP.NET > ASP.NET Web Forms and ASP.NET > ASP.NET MVC. In short he was saying that the core understanding of ASP.NET, the core features and the core uses of the platform are bigger than a single implementation (tool) could be. Sure, you need to learn a new tool, but you aren’t starting at zero if you know the platform.

    Silverlight_h_rgbWhy I am bringing this up? It is because of the discussions I have been having about another tool recently: Silverlight. We are approaching the panic stage on this tool due to rumours of it’s demise. However it is VERY important to take a step back and see what the platform is and how knowing the platform means that a tool can move along and we are still able to work/code/make money etc…

    The platform Silverlight uses is XAML based UI technologies, a core set of how we can layout UI components using an XML dialect called XAML. This platform also has lots of options for things like binding, the MVVM patterns and so on that are either difficult or impossible to do with other UI technologies (like WinForms for example).

    XAML based UI technologies started with a single tool: WPF – an implementation of the platform designed to run on top of the .NET Framework. A second tool, Silverlight, later appeared – this is an implementation of the platform designed to run as a plugin in a browser. A third tool, Silverlight for Windows Phone 7, came next and while very close to Silverlight it had it’s differences as it was an implementation of the platform for the phone. In the last few months we have had the forth implementation of the XAML based UI technologies appear: WinRT. This is the Windows Runtime in Windows 8 and when you develop with C#, VB.NET or C++ your UI technology is just another implementation of the platform.

    Every implementation of the platform has been different, some in big ways and some in smaller ways but the core of the XAML based UI technology platform hasn’t changed and there is not a single rumour, plan, or hint that we are even close to seeing the end of XAML based UI technologies. We may see a tool end of life and die (like some rumours say about  Silverlight) or other tools just find completeness and not need new work done (like WPF if) but the platform remains and grows and learning a platform is always more important/powerful/useful.

    19 Oct 2011

    Tech·Ed Africa: Slides, Scripts & Thoughts

    WP_000405WOW! I am sitting here under s a fake tree in a fake city that is Micropolis (also known as the Tech·Ed Africa 2011 expo, and it is AMAZING!). I have just finished my third and final presentation at Tech·Ed Africa 2011 and I just wanted to say THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU to all the people who attended my talks!

    This year not only has an amazing expo, but the audiences have been by far the BEST EVER! A special thanks to those who braved 8am to see my .NET 4 talk – 2min before I started I thought “I need sleep”, 2min after the energy from the audience was flowing and I never looked back at what I felt was a great talk, so thank you! Smile

    what it looks like from the presenter at #techedafricaA special work of thanks to Suliman and DPE (it is their fake tree I am sitting under) for arranging this and the opportunity to present! I also want to say thanks to the technical team at the event, without who you would not see or hear me, and they were fantastic this year!

    For those who attended my talks, or those who couldn’t below are the slides, scripts and misc files used in the talks!

    (for those in an RSS reader or on the home page, click read more)



    Power features in .NET 4: Investigating the features of .NET 4 which you don’t know about

    File downloads

    Extend Visual Studio 2010

    File downloads

    Building Business Applications with Microsoft Visual Studio LightSwitch

    File downloads

    Pages

    dontclickme