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

C# Reactive Extensions - Buffer and Window

I was going through Buffer and Window in RX, thought a few examples would help clear the differences. First create a buffer of even numbe...