Wednesday, 27 June 2012

WPF: Create your own style

Today found this cool tool: http://thematic.codeplex.com/

Using this tool you can create your styles, just in case you don't have the expert designer, you always wished you had, in your team.

Will try to create to my own and post it here soon :-)
 

Tuesday, 26 June 2012

WPF: Selecting a style at runtime

Recently I got hold of around 6 styles and needed to try them to see which one fits perfectly in our application. We can either change the <Application.Resources>, add a <ResourceDictionary> to set the style or we could do it dynamically to see the results.

Where to get the styles from?

There are few style available on web. One is at http://wpfthemes.codeplex.com/
Or create your own using http://thematic.codeplex.com/

Using it in Application.Resources:

-> First we add the XAML file containing the style to the project.
We add the file “BureauBlack.xaml” to the project

-> In App.xaml of application we write:
<Application x:Class="StyleSelector.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary Source="BureauBlack.xaml"></ResourceDictionary>
    </Application.Resources>
</Application>
Results:
Without style image   
With:

 image  

(there is some problem with the Style, it doesn't set the Window background color)

Setting style in code

Now let's try to set the style of a window in code. Here is a method which takes in a XAML file name (containing styles and added to project). We create a new ResourceDictionary object and set it to the Window's Resource collection.
        private void SetStyle(string xamlFileName)
        {
            //clear the resources
            this.Resources.Clear();

            if (!string.IsNullOrEmpty(xamlFileName))
            {
                //load new resources
                ResourceDictionary resDict = new ResourceDictionary();
                resDict.Source = new Uri(xamlFileName, UriKind.Relative);

                //merge the resources to preserve any other resource you may have added
                this.Resources.MergedDictionaries.Add(resDict);
  
                //or to overwrite and avoid memory leak you could also do this
                //this.Resources = resDict;
             }
        }        


We can use this method in the "Set Style to:" Combo Box selection changed event.
 

Wednesday, 6 June 2012

WPF Links

Some useful links I found today:

-> The technique described in this link is useful when we want to bind to a view mode's property (or any parent's data context) from a data column. (we can't use RelativeSource there)
http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/

 -> Nice use of attached properties here:
http://www.thomaslevesque.com/2011/10/01/wpf-creating-parameterized-styles-with-attached-properties/

Sunday, 3 June 2012

Ideal skills of a developer

A rough skill set of developer with more than 5 years of experience. Do you find anything missing?
 
Practices: 
  • Test-Driven Development
  • Continuous Integration
  • Domain-Driven Design
  • Dependency Injection 
  • Agile (SCRUM) Project Methodology
  • Design Patterns
  • ReSharper
  • SCRUM
Technologies: 
  • C# 
  • .NET 4.0
  • ASP.NET MVC Framework 
  • Entity Framework or NHibernate
  • SQL Server 2005, 2008
  • WCF
  • LINQ
  • OOP 
  • JavaScript
  • jQuery
  • CSS/XHTML
  • Unit-Testing
  • Workflow Foundation
  • Debugging using WindDbg, Perfmon, DebugDiag
  • Nant, Nant-Contrib

Thursday, 17 May 2012

Programming Windows - 6th Edition

I still remember reading Programming Windows 5th edition in our college. The book was very thorough and gave a nice introduction to all the Windows programming concepts, although we were more interested in API we could use to get the password text on a window or hacking the key strokes ;-)

But it's been a long time. That was the PC era. Now we have tablets and mobile ruling our lives. New toys for new era. And so we have a new book from our guru Charlez Petzold on how to program these toys.

http://www.charlespetzold.com/blog/2012/05/Programming-Windows-6th-Edition-Preview-Ebook-Is-Here.html

What is interesting about book's offer it is only $10, but the book is not yet finished yet - only 7 chapters. Windows 8 is still under consumer preview - and so I think the book is following the release cycle of Windows 8. We live in interesting times.

I am buying this book, are you? Link to buy

Edit: Well I just bought it.

Kinect Resources

Started learning how to program Kinect. Must say we live in interesting times.
Links:
- Project done at NUS using Kinect: http://hci.comp.nus.edu.sg/?page_id=273

Books:
- Free e-book at i-Programmer
http://www.i-programmer.info/ebooks/practical-windows-kinect-in-c.html

- Meet the Kinect



- Beginning Kinect Programming with Microsoft Kinect SDK




Monday, 14 May 2012

Links to Debugging Resources

This is a post to store all links to videos, blogs, PDFs relating to debugging .NET applications. I have become particularly interested in this area and getting down to details such heaps, clr-stacks, GC, analyzing dumps is so much fun!

- Tess Ferrandez:

Previously an ASP.NET escalation engineer at Microsoft, based in Sweden, now working in developer evangelism team. But still her blog has some very good info. to get started with debugging. You should check out the labs she has posted on her blog which show how to resolve performance problems.

> Blog: If broken it is, fix it you should
> (video) Session: Debugging .NET Applications with WinDbg, Developer Conference, Sweden 2009



 - Channel 9

More recently there are 6 videos posted on Channel 9 around .NET debugging by Bradl Golnaz. I have seen two and they look good.
Diagnosing Application Issues - 01 You can find links to all the videos on this link.

- MSDN
Delay's Blog: This post has some good links to other valuable posts.

- PDFs

SOS – “Son of Strike” introduction by Mark Smith.

...more links to be added soon...

ASP.NET MVC Web Sites (for study)


Today found out Suteki Shop at this address: http://code.google.com/p/sutekishop/

Since it is open-source and uses the technologies such as ASP.NET MVC3, MVC Contrib, NHibernate, Windsor; it would be interesting to look at.

Another one is Nerd Dinner. http://www.nerddinner.com/. Its source can be found here: http://nerddinner.codeplex.com/

Happy MVCing! 

Wednesday, 2 May 2012

WPF: Dynamic Menu

In one of projects I am working on, we have a requirement of showing ‘recent files’ used by the application. The files used by the application are XML files – no custom extension.

Our goal is:

 image

For this task we need the following things:
- a RecentFiles class:
    - should contain the list of recent files
    - should have methods to load/save the list to disk (persistence)
    - should have methods to add a recent file used or delete a non-existing file
- a MenuItem (with children) to show the list

Here is the RecentFiles class:

public partial class RecentFiles
    {
          private ObservableCollection<string> filesField;
          public ObservableCollection<string> Files
          {
              get
              {
                   return this.filesField;
              }
              set
              {
                  this.filesField = value;
          }

          //members for persistence – Load, Save
         //you can find the full class definition in attachments
}

In the Windows.cs, we have a view model WindowViewModel having a property named AppRecentFiles.

Code in WindowViewModel:
      public RecentFiles AppRecentFiles { get; set; }

Code in Windows.cs:
     this._mainWindowViewModel = new MainWindowViewModel();
      this.DataContext = this._mainWindowViewModel;

Now the XAML part:

<MenuItem x:Name="mnuRecentFiles" Header="_Recent Files" ItemsSource="{Binding AppRecentFiles.Files}">
    <MenuItem.Resources>
        <Style TargetType="MenuItem">
            <Setter Property="Command" Value="{Binding ElementName=mnuRecentFiles, Path=DataContext.RecentFileChosenCommand}" />
            <Setter Property="CommandParameter" Value="{Binding}" />
        </Style>
    </MenuItem.Resources>
</MenuItem>


And you are done with the basic infrastructure.

Now all we have to do is:
- add an item to the AppRecentFiles.Files list whenever we load a new file (from the Load option in menu). Tip: add the new item at top of list so that it shows as first item on the menu.
- remove file from list if the user selects a file from 'recent files’ is not found, perhaps after a confirmation message box
- load the recent files by using RecentFiles.LoadFromFile() method – usually done during Window load or app start
- and save (persist) the list by calling RecentFiles.SaveToFile() on App close or window close

Friday, 20 April 2012

There is a new pattern in town!

Just read this MSDN article about how the LightSwitch team modified (or extended) the MVVM pattern. Hold your breath it is called - MVVMVMMD or MV3.

Interesting approach, but if we want to change the view let's say add color - do we go back and change the IPropertyViewModel interface?

Article here:
 http://msdn.microsoft.com/en-us/magazine/hh965661.aspx

Wednesday, 11 April 2012

Slow TFS Performance

Recently the build time of one of our core projects on CruiseControl build server increased substantially. It went from ~8 min to ~20 min.

Upon investigation we found that the "get latest" step by CruiseControl was the bottleneck. I was also facing this problem in Visual Studio 2008, the IDE would hang for about a minute or two when ever get latest was issued. I thought the problem is with VS - probably the general (bad) impression of VS led me to this conclusion. But it was wrong to assume, the problem was with the TFS and how we map the several projects to our local folder.

We removed all unnecessary workspace mappings and also the root mapping. Now there is no local folder mapped for $. And the results are too good. Accessing TFS has become faster and overall performance of Visual Studio 2008 has also improved a lot.

Links which helped:
http://zouak.com/2010/03/24/tfs-slow-in-source-control-operations-workspace-mapping-to-blame/
and the original source: http://blogs.msdn.com/b/granth/archive/2009/05/21/large-team-foundation-server-performance-characteristics.aspx


Shorts - week 3, 2022

Post with links to what I am reading: 1. A very good post on different aspects of system architecture: https://lethain.com/introduction-to-a...