Tag editing in a WPF TextBox

2019-01-21 17:02发布

问题:

I want to implement a custom TextBox that will allow me to edit tags. Hotmail's "To" TextBox is the best example I can think of:

Also Facebook's "To" implements the same concept:

Oh yeah, and StackOverflow does it too to tag a question :)

Does anyone have some experience in building something like that in WPF? What would be the first steps that I should make?

回答1:

I believe this Tokenizing control does most of what you're looking for:

http://blog.pixelingene.com/2010/10/tokenizing-control-convert-text-to-tokens/



回答2:

I'd try the following:

  • implement a TagEditor, which has the functionality to edit a single Tag (based on an AutoComplete TextBox that is swapped with a TextBlock once an existing Tag has been recognized or editing is ended)

  • create an DataTemplate that uses the TagEditor

  • create an ItemsControl that utilizes the DataTemplate

that breaks it down to three challenges, of which only the first is a bit tricky, but solveable with the given keywords and stackoverflow ;-)



标签: wpf textbox