.Net Tips – Collating partial class files

You know how Visu­al Stu­dio neat­ly col­lates all the rel­e­vant files (the XAML and the code behind file in this case) for you when­ev­er you cre­ate a new user con­trol or page in WPF:

image

need­less to say, in any siz­able UI project this makes life hell of a lot eas­i­er nav­i­gat­ing through the solu­tion!

How­ev­er, the same sup­port is sad­ly lack­ing for nor­mal par­tial class files.. for instance, if I ever want­ed to slice up my class into par­tial class­es in sep­a­rate files to bet­ter orga­nize (and make perus­ing eas­i­er) a bloat­ed class file:

image

Visu­al Stu­dio by default doesn’t col­late the par­tial class files for you, but there’s a quick and easy (albeit man­u­al) way to do this your­self in a few steps:

1. unload the project and edit the .csproj file

image

2. edit the entries for the files you want to col­late to add a Depen­den­tUpon child ele­ment, e.g.

image

3. save, and reload project

image

Voila!