WPF ListView的GridView复制到剪贴板
我有一个如下所示的 GridView:
<ListView ItemsSource="{Binding Path=Foo, Mode=OneWay}">
<ListView.View>
<GridView>
<GridViewColumn Header="Full name"
DisplayMemberBinding="{Binding Path=FullName}" />
我所希望的是,当按 Ctrl + C 时,所有项目(或选定的项目)都会复制到剪贴板。目前还不是。我正在使用 WPF 3.0。
WPF 列表框复制到剪贴板 部分回答,但我需要的似乎更简单,我想有也是一个更简单的解决方案。
PS:这个GridView不支持内置的列排序等。如果您知道更好的免费控件并且支持复制,请随时建议它作为解决方案。
I've a GridView like follow:
<ListView ItemsSource="{Binding Path=Foo, Mode=OneWay}">
<ListView.View>
<GridView>
<GridViewColumn Header="Full name"
DisplayMemberBinding="{Binding Path=FullName}" />
All I wish is that when pressing Ctrl + C all items (or selected items) are copied to the clipboard. Currently it's not. I'm using WPF 3.0.
Partially answered by WPF listbox copy to clipboard but what I need seem simpler and I guess has also a simpler solution.
PS: This GridView doesn't support built-in column sorting and so on. If you know a better control that's free and support copying feel free to suggest it as a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我花了一些时间来回答这个问题,所以我是这样做的,以节省其他人的时间:
将数据复制到剪贴板的函数,它还解决了在结果字符串中以正确的顺序获取行的问题:
我仍然当我将内容复制到剪贴板时,偶尔会出现 COMException 问题,因此需要 try-catch。我似乎已经通过清除剪贴板解决了这个问题(以一种非常糟糕和懒惰的方式),见下文。
并将其绑定到
从以下位置调用的 Ctrl + C:
显然,这是从上面的链接复制的很多内容,只是进行了简化,但我希望它有用。
Took me some time to answer this question, so here's how I did it to save someone else time:
Function to copy the data to the clipboard, it also solves the problem of getting the rows in the right order in the resultant string:
I still have occasional issues with the a COMException when I copy stuff to the clipboard, hence the try-catch. I seem to have solved this (in a very bad and lazy fashion) by sort of clearing the clipboard, see below.
And to bind this to Ctrl + C
which is called from:
Obviously this is copied a lot from the link above, just simplified but I hope it's useful.