Copy a ListView’s Items to the Clipboard
First we need to extract the selected items from the ListView. This can be done by iterating over the SelectedItems collection and applying the bindings, which we can find in the Columns collection, to each object. That allows us to use format strings and converters which have been declared in the XAML. For each selected item, we append a line to the result.
Then we need to wrap this in an attached property. This approach is similar to what Michael Brown used to sort a grid. When the attached property is registered, we add a command binding for the copy-command to the listview’s command bindings.
When the command is executed, we just call the extension method on the listview and copy the result to the clipboard. There are three more attached properties you can use to set the delimiter, the quotation marks and whether or not to include the headers in the output.
Howdy, and nice to see your first post!
Yesterday I finished setting up my IDE (after several ours of fighting bugs) and am right now getting familiar with all the XAML I knew so far more or less superficially. Perhaps your blog will be a good source for inspiration … 🙂
Anyway you’ll definitely need to go over the formatting of your post; at the moment everything looks a bit shaken and tangled, pictures floating around at random positions …
grubbrother
March 11, 2009
Thanks! I changed the formatting of the pictures. It looks better now
jannmueller
March 11, 2009
Hallo Jännchen!
Megan Snively
March 15, 2009