Friday, November 12, 2010

Prevent WPF Tree View nodes from getting selected.

By default all the nodes of the WPF tree view is selectable. If some how we had a requirement that the roots nodes can not be selected rather only the child nodes will be selectable we need to customize one single property “focusable”. If we set the focusable property of any node to false then the node will not be selectable. pretty small thing but worth sharing because in MSDN forum one developer asked for this.

Bello a simple code sample is given

        <TreeView Height="251" HorizontalAlignment="Left" Margin="45,30,0,0" 
Name="treeView1" VerticalAlignment="Top" Width="197">
<TreeViewItem Header="Yahoo" IsManipulationEnabled="False" Focusable="False">
<TreeViewItem Header="d" />
<TreeViewItem Header="c" />
<TreeViewItem Header="b" />
<TreeViewItem Header="A" />
</TreeViewItem>
</TreeView>






Hope this will help, Note that if you have some binding with the tree grid and you want to achieve the same as above you might need to use triggers.

Friday, October 8, 2010

Most widely used WPF client application development frameworks

I done some research on WPF client application development frameworks and eventually found out three most used framework and one yet to be mature framework. I thought its worth sharing the research result

1. Prism

http://compositewpf.codeplex.com/

Impression : Most advance framework

2. Caliburn

http://caliburn.codeplex.com/

Impression : Advanced  framework

3. Cinch

http://cinch.codeplex.com/

Impression : Solved particular set of problems and can be used along with other framework

4. WPF Application Framework (WAF)

http://waf.codeplex.com/

Impression: Primitive and useful framework to develop MVVM pattern based application

All the application framework used MVVM pattern to develop the applications, I am sure this frameworks are worth learning and will definitely help us in career.

Friday, September 10, 2010

Typical Code Smells

While doing daily development in various project we often found lots of coding standard problem, we just don’t know the appropriate vocabulary for that, Today I am providing a list of all code smells that can be found in codes, We would elaborate and learn about each code smell. the list (rough) is given bellow, if anyone finds more code smell please provide in comment section.

  1. Dead code
  2. Duplicate code
  3. Comment
  4. Long Method
  5. Large Class
  6. Oddball Solution
  7. Primitive Obsession
  8. Switch Statement
  9. Speculative Generality
  10. Long Parameter List
  11. Conditional Complexity
  12. Combinatorial Explosion
  13. Alternative classes with Different Interfaces
  14. Inappropriate Intimacy
  15. Indecent Exposure
  16. Refused Bequest
  17. Black Sheep
  18. Data Class
  19. Solution Sprawl
  20. Feature Envy
  21. Temporary Field

In future post we would discuss mostly all about the smells.

Sunday, August 15, 2010

Is Excel Present in client machine?

In one of our application we had to make sure that whether client have excel installed or not. We tried few codes and have some experience while resolving the solution. Bello the solution code is given to detect if client have excel 2007 installed or not.
 
The bellow code works fine. But it fails one single time. If the user installed excel but never run it. The registry keys are not built until the user run excel for the first time. so we had to change our message to inform user as “You don’t have excel or you didn’t run it after install, if you have install please run it for the first time and try again” some thing like this.
 
private static bool IsExcelPresent()
{
var key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office");
if(key!=null)
{
string[] subKeyNames = key.GetSubKeyNames();
if(subKeyNames.Contains("12.0"))
{
var excelKey = key.OpenSubKey("12.0\\Excel\\");
if(excelKey!=null) return true;
}
else
{
return false;
}
}
return false;
}


 

Eventually we got rid of the obstacle and found a very interesting component called SpreadsheetGear and used that component. we bypassed all the excel requirement using this component.

 

There are some more solutions on the web to you guys can also try those. Bellow a yet another code sample is given.

 

private static bool IsExcelPresent()
{
try
{
Type officeType = Type.GetTypeFromProgID("Excel.Application");
return officeType != null;
}
catch (Exception ex)
{
return false;
}
}


Another code sample to detect excel which using registry key search

 

private static bool IsExcelPresent()
{
RegistryKey key = Registry.ClassesRoot;
RegistryKey excelKey = key.OpenSubKey("Excel.Application");
bool excelInstalled = excelKey == null ? false : true;
return excelInstalled;
}


 

 

Thursday, July 15, 2010

Simple Yet powerful html Content rotator

I found this simple yet powerful html content rotator and using in few of my projects. I think its worth sharing with the community. The library named

jShowOff: a jQuery Content Rotator

You can download the script from this location. It requires two file only, on css which you can copy to your own css file and the other one is of course the java script , there are two distribution for this library, I strongly suggest that you should use the min version.

http://ekallevig.com/jshowoff/

There are some comprehensive set of examples given in the home page for the library. I would suggest to download and look for this examples.

image 

Best of luck and happy programming.

Thursday, June 10, 2010

Rounded Corner and other stuff in IE7 or IE8

Often we need to have rounded corner support for our html content, filefox, crome, safari and latest version of IE9 have native support for rounded corner for html div and other supported html elements. But Alas! we don’t have support in IE6, IE7 or IE8.

An interesting website is http://border-radius.com/ where we can generate rounded border radius. just visit this site and add your desired pixel. It will generate the required css for you.

image 

It’s a copy and pest effort. Now if we need rounded corner in pre IE9 browsers we need some thing out of the box. Then come the custom css and JavaScript libraries and some time html “.htc” behaviors files.

In first option we are going to talk about css3pie it’s a simple yet powerful tool to get some html5 support in old ie browsers. You can download the libraries from its homepage at http://css3pie.com/image

Add what ever border you need and at last include behavior:url(/pie.htc) that’s it.

Next we are going to see an query based rounded corner support, http://jquery.malsup.com/corner/ this is the site where from you can download the library its s single file and required to have query in advance. the use is very easy. bellow an screen shot from original site is given.

image

Try it you would love it. I am sure lots of you are already using it. Good luck and happy programming.