Improvements in WPF in VS 2015 and .Net 4.6


From a long time in software development world it was assumed that Desktop applications will be dead. This dodo was there more than half of decade. But it’s not the reality because the LOB (Line Of Business) applications are still heavily used as desktop applications in various businesses e.g. Reporting, Data analytics or simple data entry form application. Talking of desktop application comes with talking about Windows forms and WPF.

Windows Forms and WPF

Windows forms have stayed as part of the softwares for a long time now they have been upgraded to WPF because of better UI and great user experience. Now the WPF have been in the market and it’s a long time now. Developers were afraid that some other technology will soon be in the market to replace the WPF. It was obvious because we didn’t hear anything related to WPF from Microsoft. But Finally, We have some news and updates from Microsoft which will give a great relief to Developers and Businesses. Because this time we have great enhancement done in WPF. In this blog post will be discussing those important changes done that will change the experience of WPF in terms of performance(A lot of requests were raised regarding the performance).

Improvements in WPF with .Net 4.6 and Visual studio 2015:

1. Profiling on the go

Now one can start profiling of WPF application. The profiler provides flexibility to choose either one or both between the CPU usage and Memory usage.
To Launch a profiler Go to Debug –> Start Diagnostic tool without debugging... (In previous post we discussed that Diagnostic tool is now part of the Debugging process)

Here’s a preview of how the diagnostic would look like:

This might look like something like this when you select the options to diagnose and start diagnosis:

When you stop the diagnosis it’ll generate the reports for each type of diagnosis selected.

These reports will contain the “Worker Thread” state, CPU usage and memory usage including the Hot Paths. To learn reading these report see MSDN detailed article.

2. Dynamic UI diagnostic tool

Those who worked extensively on WPF apps knows the pain of debugging the UI. That time there were tools used to debug the UI stuff. Now this “Most Wanted” feature is now can be found in Visual studio 2015. The enhancements are not just spying but giving the flexibility to change the Live UI items while running and debugging the application is Just made is “Awesome”.
The diagnostic tools are known and available as “Live Visual Tree” and “Live Property Explorer”. To enable this tool go to “Debug” menu item while debugging and goto Debug –> Windows –> Live Visual Tree.


Now you can see following windows. There are options to Enable/Disable the dynamically finding the UI elements from the UI and changing the properties accordingly. Awesome stuff “Try it yourself”.


This will change a lot of things and will help speeding up the development process.

3. XAML Editor vs Designer window

Developers are rarely use the designer window to design the component. Most of the time they’re relying on pure XAML coding stuff. Previously It was pretty annoying to have designer and XAML editor window together. Now you can “Turn off” the designer if you don’t like it there. Simply go to Tools –> Options –> XAML Designer. And turn it off by unchecking the Box.


I know you all must be liking these changes so far. This is not all there couple of more stuff that you can checkout and might help you with Development.
Here are couple of more items which are in the List which are shipped with .Net 4.6 and Visual Studio 2015 RTM:
4. Deferred/Lazy loading of Visual elements
5. UI Virtualization for data intensive applications
6. High Definition devices support
6. DirectX interoperability
7. Support of Modern device (Touch screen device)
8. Multi-image cursor file support in System.Windows.Input.
9. Support for transparent child windows.
10. Improved double tap gesture recognition by using common threshold distance from registry.
11. Improved text selection through double tapping the WPF TextBox control.
12. Improved reliability of stylus input for the WPF ComboBox control.

These are the improvements which can be posted as a dedicated blog posts so not discussing everything in this post. But future of WPF is bright with these enhancements. XAML and C# the combination is going to be there in the Market for long time.
For more details watch this Channel9 Interview with WPF team.
Note: These are the features which I liked most(out of those all shipped in RTM)and are are based on my own research.

New debugging features in VS2015

This is short post about the things I liked much from the new updates in Visual studio 2015. In this post I’ll be discussing about the new improvements I observed during debugging in Visual Studio 2015.  These features are being frequently asked by Developers via UserVoice and Microsoft regarded the ideas and here we are now.

1. Last statement execution time

This would be a more helpful for developers writing performance sensitive application. Though the time shown can vary from actual time because if you’re in “Debug” mode then it has it’s own time to load symbols and other debugging data. But it’s more than just a value added. One can easily see the estimated time of execution time of an statement by “Stepping Over” during debugging. Great feature!!!


2. The Diagnostic tool. (Keep eye on your CPU and Memory usage while debugging – No more profiling)

This is the most awaited feature. Now developers don’t actually need to go for profiling because everything is being provided right at spot in early stage of devleopment. Memory, CPU usage and other stuff, Just launch the the visual studio 2015 debugger and see for yourself. All of this is achieved with the help of Intellisense and Run time profiling of assembly.


3. Linq Expression evaluation (Most awaited feature – YAY!!!!)

Visual studio 2015 now enabled with feature to evaluate LINQ expression on the fly while debugging. Now one can evaluate the collection objects on the fly with LINQ. This was much awaited feature(…remembering those crazy days). LINQ is one of the most liked feature of C# language. LINQ expression can be used in either via “QuickWatch…” or “ImmediateWindow”. How’s that sound?



4. Edit and Continue on x64 Machines

Previously the feature was only available for 32 bit machine in earlier versions of visual studio. But in VS2015 it’s more enhanced and generated the symbols and other debug information on the fly. The Integration of Intellisense is more improved and much faster. Now any application including WPF are now able to “Edit and Continue” during debugging.

There’re are more improvements that I’m planning to share in upcoming posts so keep an eye if you like these posts.

Using stylecop with Code analyzer in VS2015

As per the styplecop project the support for Visual studio 2015 is not yet ready. Not sure if there’ll be any support available in coming future because VS2015 now have it’s built-in code analyzer which can adapt to any provided Code analyzer and run the ruleset accordingly against the project code files.

To get the style cop running with Visual studio 2015 follow below steps:

Installing Stylecop.Analyzers(currently in Pre-release version) nuget package in Visual studio 2015 project. Make sure to select “include prerelease” checkbox before searching -

I like the new Nuget package manager, Professional.

After the installation of Stylecop.Analyzers Nuget package, Expand the Reference tree and look for the Analyzers -

Now Right click on it and select “Open Active Ruleset”. This will open up the list of Analyzers and their rule sets.


Now you can select and customize the Ruleset to run for your code. Now when you press save this will add a new file “<your projectname>.ruleset” with-in the project. This customized Ruleset file can be used across the projects.

Managing the Rulesets across Projects
To manage the Rulesets across the projects you can configure the mapping of Ruleset. See follow below steps:
1. Click on Analyze from Menu and select “Configure Code Analysis for solution


This will open a windows and provide the option to choose which Ruleset to run against each project. You can choose the same file that you have created for all projects. OR you can go for separate rulesets files for individual projects.


Now, that you have created a custom rule set file and setup the Ruleset for projects in a solution. Now you can launch the code analysis on Solution level.

Launching the Code analysis

Analyze –> Run Code Analysis for Solution (Allt + F11)

This should gives results in the Error window.

Now you have the code analysis results from your old friend styleCop. Hope this would help you util we hear from other sources.
Thanks to John Koerner’s post for guiding towards the stylecop.Analyzers nuget package thing.

Updated Csharp 6.0 features in RTM VS2015

There are plenty of Blogs and article already posted about the C# 6.0 new features. But I observed there are some changes from the features in the preview and newly shipped with Visual Studio 2015 RTM (Of course some improvements based feedback from Preview). In this blog post, I’m trying to address those changes as well as describing new features altogether.
Below is the list of enhancement delivered in the RTM version of CSharp 6.0(Excluding VB enhancements which were mentioned in the source, Also I have added quick samples to illustrate the enhancements):

Feature Example
Auto-property initializers public int X { get; set; } = x;
Read-only auto-properties public int Y { get; } = y;
Constructor assignment to getter-only autoprops public DemoClass{
   Y = 15;
Static imports using static System.Console; … Write(4);
Index initializer > new JObject { ["x"] = 3 }
> var numbers = new Dictionary<int, string> {
    [7] = "seven",
    [9] = "nine",
    [13] = "thirteen"
Await in catch/finally try … catch { await … } finally { await … }
Exception filters catch(E e) when (e.Count > 5) { … }
Partial interfaces Partial Interface I1
Multiline string literals "Hello<newline>World"
Expression-bodied members public double Dist => Sqrt(X * X + Y * Y);
Null-conditional operators customer?.Orders?[5]
String interpolation $"{p.Name} is {p.Age} years old."
nameof operator string s = nameof(Console.Write);
#pragma #Disable Warning BC40008
Read-write props can implement read-only interface properties <"In my TODO items"> 
#Region inside methods     public void TestMethod()
        #region MyRegion

CRef and parameter name     /// <summary>
    /// Initialize with <see cref="Program(DateTime)
    /// </summary>
    public Program(DateTime timestamp)

Extension Add in collection initializers See the explained example below
Improved overload resolution <"In my TODO items"> 

Most of the features enhancements mentioned above are self explanatory, So I’ll be explaining only interesting ones those need some explanation.

Properties Enhancements

We have couple of enhancement in Auto properties. With new enhancements the compiler generated generated the required code and save some developers time. Now the properties can do:

public class Person
    // Readonly properties are not allowed to be initialized in Constructor
    public int Id { get; }
    public Person()
        // Initialzing the readonly property.
        this.Id = -1;
    // Initialize the property right at the declaration
    public string Name { get; set; } = "Jhon Doe";
    public int Age { get; set; }
    public string Title { get; set; }

Note: Static properties are not allowed to have constructor initialization.

Static Imports and Extension methods

Now the C# allows to import the static members of another class without using the class name. So they can be used directly into another class. This feature is extended to include the Extension methods. Also the Improvement was done with Using now one must use Static keyword to import the static members.

using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Linq.Enumerable;
public class Demo
    public void Print()
        var cultures = new string[] { null, "en-NZ", "en-US", "en-AU", "en-GB" };
        Write("The static methods are directly available.");
        // Here Range() is static so only simple static methods are allowed to use. 
        // Extensions are static 
        // but they are not be allowed to use directly. 
        // This is taken care of very carefully to keep the 
        // separation in these two types of features.
        WriteLine(Range(0, 10).Where(x => x % 2 == 0));

Extension Add method for Collection Initializers

This looks interesting but this feature was already there in VB.Net surely it was brought back home to C#. It could be value added where Generic collection are need to be initialized with complex types. Here’s a sample how it works:
E.g. below is a simple entity representing a complex type (Let’s assume)

public class Person
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public string Title { get; set; }

Now C#6.0 allows use to write an extension Add method for a Collection: E.g.

public static class Extensions
    public static void Add(this List<Person> source, int id,  string name, int age, string title)
        source.Add(new Person {
            Id = id,
            Name = name,
            Title = title,
            Age = age

If we want to use this collection of type Person in the code then collection initializer would lesser work:

List<Person> List = new List<Person>()
    { 1, "Ramesh", 22, "Mr." },
    { 2, "Julia", 24, "Ms" },
    { 3, "Paula", 12, "Mrs." },

This might not look like a big change but surely going to add some values in some cases e.g. Unit tests where collection are need to be created for Fake data.
I hope most of us will enjoying these feature though it will take some time to pick them as handy feature. Those which are marked as “TODO” item, I’ll be working on exploring them and may be writing about them in upcoming blog post.