Saturday, October 6, 2012

Editable wpf control

Recently I've involved myself in a fun project which is basically a plugin for outlook that can automatically tag my mails based on some regular expression. During the time I noticed that I might need a control that can switch between different mode from view to edit and vice-versa. The control should also be able to display a list of possible tags for the particular mail item. I searched and searched for this kind of free control and could not find any. So I decided to build my own, which is in a way fun too. Rather than building this in winform, I decided to stick with wpf. If you are wondering why then you surely are missing something. I'd not even think of building such control, if wpf wasn't there. Styling and adding behavior in wpf controls are so much easier than doing the same in winform. I remember back then when I had to build a custom grid control with group header in winform. After that I never thought of custom building anything in winform.

So this is just a basic control with the functionality as described earlier above. It is derived from textbox control and modified the template itself. So coollll.... Just few lines of code to switch back and forth between textblock and the textbox content presenter itself and my basic model is almost ready. The control can also behave like autocomplete like I said earlier and for that, after scratching my head for a day or two I decided to make it MVVM friendly. The user can provide the autocomplete list data provider which is basically a class that implements IAutoCompleteDataCollector. 

public interface IAutoCompleteDataCollector
        void GatherData(AutoCompleteDataArgs arg);

On top of it you can also switch the datatemplate of the autocomplete listbox. 

I suggest you to check out the source code and extend it on your own. Please remember that this is still in it's infancy. I might or might not take interest in further extending this control. And also note that some of the things have been borrowed from different sources such as the cross button, you can see in the listbox control in a sample mainwindow form. 

Please do not forget to send me a link to such wpf controls if you have any.