About Me

reno, NV, United States
As of 2011, I have ten years experience in various technologies as C#, WPF, Java, J2EE, C++. For the past three years, I have been extensively working on various .net and java technologies including but not limited to WPF , C# , WCF and composite application guidance (Prism ).

Monday, May 11, 2009

Resharper 4.5 is kicka$$ :)

There is a newer release of Resharper, version 4.5 available. If you haven’t put your hands on it, I suggest you do. I could see a lot of improvements compared to the previous versions (especially performance). All licenses purchased after Dec 21, 2007 qualify for a free upgrade to ver. 4.5. According to their website these are some of the new developments.

§ Performance and memory consumption: When working on large solutions, you’ll feel a great deal of difference between ReSharper 4.0 and 4.5.

§ New solution-wide warnings and suggestions: Analyze usage of non-private types and type members within your whole solution.

§ Visual Basic 9 support: ReSharper’s cross-language refactorings and editing experience enhancements now provide support for VB9 code.

§ Extended setup for naming conventions, which are now supported by all ReSharper features.

§ New Inline Field refactoring and enhancements in existing refactorings.

§ Go to Implementation: Go from usage of a class or method straight to its end implementation, bypassing abstract classes and/or interfaces.

If you would like to see a quick demo of all the features, here they are... If you like it and would like to download the new 4.5 release follow this linky. Here is the 4.5 feature map.

If you are updating your Resharper.. Please copy your user name and license key on a notepad as a backup.
Happy Coding,


Thursday, April 23, 2009

VS 2008 Templates for Composite Application Guidance (Prism v2)

Most of the credit for this post goes truly to Knom who created the initial versions of Visual studio templates. I have been using them for a while, though I always felt that it is broken or incomplete, so here is the newer version.


The revisions in this modification are
a) The new version works only with February 2009 Composite Application Guidance. It refers to the IModuleCatalog introduced in this release.
b)The references like Microsoft.Practices.composite broken in the previous release are fixed now!
c) The new dlls like Microsoft.Practices.composite.presentation.dll are referred instead of Microsoft.Practices.composite.wpf.dll
d) Namespaces in view and presentation models are fixed in this release.
e) every module can have its own name and the same with ModuleController.
f) Unnecessary imports have been removed.
g) Slicker interface.

If you like this, please goto knom's page and contribute. I dont need any! (may be a comment if it is useful to you !) You can completely write a Prism application in less than ten minutes using this application.


a) If you have not installed Composite Application Guidance, install it here.

b) Download the Visual studio templates for composite application Binaries here.

c) Unzip this and you will find three files.
* install.bat does all the work to setup the templates (run the .VSI and add the .DLL to the global assembly cache)
* CompositeTemplateWizards.dll contains the Wizards used from the project templates. This assembly must be installed into the GAC.
* Templates.vsi is VSI installer package with all the templates (need the wizard assembly in the GAC).

d) Run the install.bat

If you are upgrading from knoms templates then just follow the same instructions and when installing, it would ask you for a over ride. Do override the old files!

Trouble shooting Notes
a) If you have more than two versions of Visual studio you might not be able to see these templates when you click "new project". In that case

Goto Programs> Microsoft VS 2008> Visual studio tools \ Visual studio 2008 command prompt

In here change your directory to the base directory where you have the install, run the following command.

gacutil.exe -i CompositeTemplateWizards.dll

Restart vs 2008 and things should start working

b) After installing the "composite application guidance 2.0" Visual studio 2008 templates, as a one time activity create a libraries folder with following libraries.

This folder will be useful in creating the Prism apps.

Tuesday, April 14, 2009

Running animations in MVVM

We implement Composite application guidance (Prism v2) in our application. Recently we wanted to run animations when something changes in ViewModel. The Viewmodel changes should initiate storyboards or run functions on view.xaml code behind.

I implemented a class ViewModelChangeDispatcher which can be useful to run animations.
You can instantiate this lightweight class from xaml as

OnSourceChangedStartStoryboard="XXXStoryBoard" />

The above VMCD is bound to Source xxxAnimation, this when changed will automatically call the storyboard...

If you want to manage multiple animations using the same, u can handle that by this code

When source is changed the event handler RunAnimation is called.

Anyway here is how I implemented ViewModelChangeDispatcher.

public class ViewModelChangeDispatcher : FrameworkElement
#region Data

public static readonly DependencyProperty SourceProperty;
public static readonly DependencyProperty OnSourceChangedStartStoryboardProperty;

// The routed event
public static RoutedEvent SourceChangedEvent;

#endregion // Data

#region Static Constructor and static methods

static ViewModelChangeDispatcher()
SourceProperty = DependencyProperty.Register(
new FrameworkPropertyMetadata(string.Empty,OnSourcePropertyChanged));

OnSourceChangedStartStoryboardProperty = DependencyProperty.Register(

//Registering the events
SourceChangedEvent = EventManager.RegisterRoutedEvent("SourceChanged",


private static void OnSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

ViewModelChangeDispatcher vmcd = d as ViewModelChangeDispatcher;
if (vmcd == null) return;

vmcd.RaiseEvent(new RoutedEventArgs(SourceChangedEvent, vmcd));
if (vmcd.OnSourceChangedStartStoryboard == null) return;


#region constructor and members
public ViewModelChangeDispatcher()
this.Visibility = Visibility.Collapsed;
this.Width = 0;
this.Height = 0;


* Source is always string.
* It is the onus of the markupextension to convert it to a string.
* */
public String Source
get { return (String)GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }

public event RoutedEventHandler SourceChanged
add { AddHandler(SourceChangedEvent, value); }
remove { RemoveHandler(SourceChangedEvent, value); }

public Storyboard OnSourceChangedStartStoryboard
get { return (Storyboard)GetValue(OnSourceChangedStartStoryboardProperty); }
set { SetValue(OnSourceChangedStartStoryboardProperty, value); }


Please let me know if you have any comments/inputs!

Happy coding!
Pradeep Mahdevu


Also refer Josh Twist's point of view on this.
joy of code
and pavan's post here...

Pixel in genie

Composite application Guidance Prism Logging

Coming from a Java web development world, I always love the ease of use of apache commons logging, I recently implemented logging in our WPF application based on Composite Application guidance (CAL or Prism v2). We use the Microsoft way of logging, Enterprise Library 4.1. Though the performance is sluggish compared to log4net, we wanted to use this for various other reasons.

This blog entry would help you set up you CAL with enterprise logging. I created a class called CustomLogger. CustomLogger encapsulates Logger. You can either resolve ICustumLogger or ILoggerFacade to use this. ICustomLogger provides interface common to Apache commons logging and ILoggerFacade provides interface common to Enterprise Logging.

First looking at registering the ILoggerFacade. The BootStrapper overrides LoggerFacade to return the customLogger.

internal class Bootstrapper : UnityBootstrapper
// CustomLogger is a custom logger implementation.
CustomLogger logger= new CustomLogger();

protected override ILoggerFacade LoggerFacade
return logger;

protected override void ConfigureContainer()
Container.RegisterType(new ContainerControlledLifetimeManager());



We register two things with the container, the ILoggerFacade and the ICustomLogger. Though there is a mere small additional cost,the benefit of this is huge, ILoggerFacade is used by the CAL to log things in trace.log and ICutomLogger is used by app to log things.

An example of logging using this interface is ...

public XXXXXXXXXPresentationModel(IUnityContainer container,
IMagCardInfoView view,
IEventAggregator eventAggregator,
ICustomLogger logger,
IMagCardCommandsView commandsView,
IRegionManager regionManager)
: base(eventAggregator)
logger.Debug("New XXXXXX Presentation model requested.");


The ICustomLogger interface looks like

public interface ICustomLogger

void Info(string message);

void Debug(string message);

void Warn(string message);

void Exception(string message);


The CustomLogger looks like

public class CustomLogger: ICustomLogger, ILoggerFacade

public void Info(string message)
Logger.Write(message, Category.Info.ToString(), (int)Priority.High);

public void Debug(string message)
Logger.Write(message, Category.Debug.ToString(), (int)Priority.High);

public void Warn(string message)
Logger.Write(message, Category.Warn.ToString(), (int)Priority.High);

public void Exception(string message)
Logger.Write(message, Category.Exception.ToString(), (int)Priority.High);

#region ILoggerFacade Members

public void Log(string message, Category category, Priority priority)
Logger.Write(message, category.ToString(), (int)priority);


Monday, April 13, 2009

WPF UI Waiting for server animated with dependency control.

Writing a WPF application often requires communicating with Server. When the WPF application requires to contact with server, we would like to show a neat animation on the UI like Internet explorer.

This listing shows a way to create an userControl which can be used in applications like

xmlns:WA="clr-namespace:WaitingAnimated" .... />

Margin="200, 50, 300, 300"/>

In the source code attached I have a toggle button which starts/stops the animation by setting the value of IsAnimated to true or false...

private void Button_Click(object sender, RoutedEventArgs e)

animatedIcon.IsAnimated = !animatedIcon.IsAnimated;

Going thru XAML in the user control which is not rocket science but still...

The Grid.Resources has a storyboard, the repeat behavior of animation is forever and the storyboard target property is Angle of the path.

Storyboard.Target="{Binding ElementName=path}"

Path is the union of two circles. The important things in path are the rendertransform origin which translates the origin to the corresponding value, i typically define rendertransform and add all children even if i dont use to keep code extensible. Path fill is the color in the circular path which is filled .

RenderTransformOrigin="0.5,0.5" x:Name="path">

Source code here.

Friday, February 6, 2009

Flying Grids using margin animation

The idea of doing this is to make the application comfortable for left handed and right handed people equally. We came across this problem when we started development of app for touchscreens. The RH people required the command grid on RHS and LH ppl on left handed respectively. There are two grids, One is a command grid (referred as commGrid) and the other is mainGrid. The mainGrid has a button Swap me! When the button is hit, the main grid and commGrid swap. the main window of the app (window1.xaml) has following grid ( superGrid).

The button_click event handler is as follows...

private void Button_Click(object sender, RoutedEventArgs e)
//calculate commGrid and mainGrid widths
double commGridWidth = commGrid.ActualWidth;
double mainGridWidth = mainGrid.ActualWidth;

//animated is a bool const at app level to check if animation is enabled.
AnimateGrids(changeDexter, commGridWidth, mainGridWidth);
GridChange(commGridWidth, mainGridWidth);
changeDexter(this, EventArgs.Empty);



The most important function where the central logic lies is AnimateGrids. Since Margin does not have a animation by itself, we can use thickness animation. I have two animations, one for each grid.

private void AnimateGrids(EventHandler postAnimation, double commGridWidth, double mainGridWidth)

* If commGrid is right
* commGrid.Margin.Left should move from 0 to -mainGridWidth
* commGrid.Margin.Right should move from 0 to +mainGridWidth
* If commGrid is left
* commGrid.Margin.Left should move from 0 to +mainGridWidth
* commGrid.Margin.Right should move from 0 to -mainGridWidth

Storyboard sb = new Storyboard();

ThicknessAnimation commGridAnimation
= new ThicknessAnimation
From =
new Thickness(0),
To =
new Thickness((isRightHanded ? -1 : 1) * mainGridWidth, 0,
(isRightHanded ? 1 : -1) * mainGridWidth, 0),
AccelerationRatio = 0.2,
FillBehavior = FillBehavior.Stop,
DecelerationRatio = 0.8,
Duration = DURATION

ThicknessAnimation mainGridAnimation
= new ThicknessAnimation
From =
new Thickness(0),
To =
new Thickness((isRightHanded ? 1 : -1)*commGridWidth, 0,
(isRightHanded ? -1 : 1)*commGridWidth, 0),

FillBehavior = FillBehavior.Stop,
AccelerationRatio = 0.2,
DecelerationRatio = 0.8,


Storyboard.SetTarget(commGridAnimation, commGrid);
new PropertyPath(MarginProperty));

Storyboard.SetTarget(mainGridAnimation, mainGrid);
new PropertyPath(MarginProperty));


sb.Completed += new EventHandler(postAnimation);



ChangeDexter is an event handler which is defined as

private void changeDexter(object sender, EventArgs e)
isRightHanded = !isRightHanded;
//Swap columns
Grid.SetColumn(mainGrid, isRightHanded ? 0 : 1);
Grid.SetColumn(commGrid, isRightHanded ? 1 : 0);

//Swap widths
GridLength gl = superGrid.ColumnDefinitions.ElementAt(0).Width;
superGrid.ColumnDefinitions.ElementAt(0).Width = superGrid.ColumnDefinitions.ElementAt(1).Width;
superGrid.ColumnDefinitions.ElementAt(1).Width = gl;


ChangeDexter is called at the end of animation.

Download source code here

Happy coding!
Pradeep Mahdevu


Blogger Syntax Highliter