Smart Search
One of the requirements is to be able to find existing contacts in the system and add them to a new job. I created a smart search where I could type a few characters of a name and it would list matches. I could then drag a matching contact over to the new job and insert it into the contact placeholder. This was simple enough, but I did run into a problem where the entity framework was creating new contact records rather than linking to the existing ones. This was because I was using separate EF context objects for the contacts and the jobs. So, when I save the new job, the context object had not recognised the contact as one that was already in the system. I fixed this by creating a factory method that returned a singleton instance of the EF context that both the contact and job data access classes could use.
Drag and Drop
To perform the drag and drop from the smart search to the new job view, I used some drag and drop code that I had used in the Prediction League application. I realised that if I was to use drag and drop extensively, I'd be copy and pasting this code into multiple views. What I really needed was to extract and generalise the code so that I could plug the drag and drop strategies in where needed. I managed to do this and learned a bit about using generics at the same time.
I'm going to look into a WPF drag/drop library on Google Code that uses attached properties to that the drag drop code can be written in the ViewModel rather than the view code behind.
http://code.google.com/p/gong-wpf-dragdrop/
No comments:
Post a Comment