Thursday 6 June 2013

Optimizing View loading performance by limitting visible elements

         Wpf can be quite a system hog, if we forget about certain optimizations. Some of them are a must, and not everyone are aware of them. One of the worst things your user can experience with the UI is clicking a button and waiting 10 seconds for the form to show up. This is why every time you have finished building your Wpf forms and views you should ask yourself a question - is there anything in the view, any particular piece of xaml, that is not visible after the view loads for the first time.

         Are there any controls, which in order for the user to see them, he or she has to click the Expander's Button or maybe switch a TabItem in the TabControl. If the answer is yes, then there's some reworking to do, and some importans milliseconds to sheer off.
         To postpone the moment of loading of most xaml elements it is sufficient to initially set Visibility to collapsed. Whatever is inside will be loaded the moment you set the visibility to visible. In case of expander and the tabcontrol it is different. Both of these controls load their "innards" despite the visibility of the content set to Collapsed. The way to overcome this is by using DataTemplates, and it's best to show it by example.

  1 <TabControl.Resources> 
  2    <DataTemplate x:Key="firstTabItem"> 
  3       <SubViews:Tab1 DataContext="{Binding DataContext.SomeViewModelProperty,
  4           RelativeSource={RelativeSource FindAncestor, 
  5           AncestorType={x:Type TabControl}}}"/> 
  6    </DataTemplate> 
  7    <DataTemplate x:Key="secondTabItem"> 
  8       <SubViews:Tab2 DataContext="{Binding DataContext.SomeViewModelProperty,
  9           RelativeSource={RelativeSource FindAncestor, 
 10           AncestorType={x:Type TabControl}}}" /> 
 11    </DataTemplate>    
 12 </TabControl.Resources>  
 13 <TabItem Header="firstTab" ContentTemplate="{StaticResource firstTabItem}"/> 
 14 <TabItem Header="secondTab" ContentTemplate="{StaticResource secondTabItem}"/



These are rather easy things to do, and the gain is quite visible if you have some more complex xaml inside your tab items.

Tuesday 4 June 2013

Norwegian Developers Conference, Oslo 12-14

        Because all of my posts till today involved some kind of coding, I though I'm gonna post something on a slightly different note, especially because of an important event that is slowly approaching.
        The event is Norwegian Developers Conference 2013 http://www.ndcoslo.com/, takes place in Oslo between 12th and 14th of June. It's one of the most interesting conferences out there, right next to Orodev. Although I can't personally visit and see for my own, I'm really fond of the videos of all the lectures they quite promptly upload. There will be some really good speakers attending ( as they do every year @ NDC ) and I can't wait for talks by Jon Skeet, Robert C. Martin, Dan North and other big personas.

I though this little post will be my "to-watch" list, so here it goes:

Wednesday
Clean Architecture and Design
Robert C. Martin
12 June 2013 11:40 - 12:40

Patterns of Effective Teams
Dan North
12 June 2013 15:00 - 16:00

Principles of Component Design.
Robert C. Martin
12 June 2013 16:20 - 17:20

Faking Homoiconicity in C# with graphs
Mark Seemann
12 June 2013 17:40 - 18:40

Reactive meta-programming with drones
Jonas Winje, Einar W. Høst and Bjørn Einar Bjartnes
12 June 2013 17:40 - 18:40

.NET Rocks - Functional Programming Panel: Type systems and static typing - saving your ass or getting in your face
Stuart Halloway, David Nolen, Don Syme, John Hughes, Carl Franklin and Richard Campbell
12 June 2013 17:40 - 18:40
(.NET Rocks coming to NDC woohoo!!)

Thursday
Hacking .NET(C#) Application: An Unfriendly Territory
Jon McCoy
13 June 2013 09:00 - 10:00

Ground Control to Major Tom
David Nolen
13 June 2013 09:00 - 10:00
( if something carries the name of a David Bowie song it has to be good, right? :) )

Abusing C#
Jon Skeet
13 June 2013 10:20 - 11:20

Asynchronous Programming on the .NET Platform
Venkat Subramaniam
13 June 2013 10:20 - 11:20

SQL Server's Last Breath
Rob Sullivan
13 June 2013 17:40 - 18:40

Friday
TDD, where did it all go wrong
Ian Cooper
14 June 2013 09:00 - 10:00

Service oriented architectures (hardcore separation of concerns)
August Lilleaas
14 June 2013 15:00 - 16:00

C# 5
Jon Skeet
14 June 2013 16:20 - 17:20


There are many more and I'll probably see many more, but lets have at least those here noted.