I want to prevent users from copying content from a column in my WPF DataGrid, which I've defined as a DataGridTextColumn
Setting ClipboardContentBinding="{x:Null}"
has not worked, which to me is the most obvious way to prevent any content from being copied.
<DataGrid.Columns>
<DataGridTextColumn Header=Field"
Binding="{Binding Name}"
ClipboardContentBinding="{x:Null}" />
</DataGrid.Columns>
I expect the output to be string.empty (or not even be included in the ClipboardContents) since the ClipboardContentBinding is set to null. Instead, it's actually copying the Name.
Edit 01:
I tried: ClipboardContentBinding="{x:Static Binding.DoNothing}"
but that didn't work. I get an exception:
System.ArgumentException: Object of type 'MS.Internal.NamedObject' cannot be converted to type 'System.Windows.Data.BindingBase'.
What does work, is setting a binding to a path that will fail. For example:
ClipBoardContentBinding="{Binding InvalidPath}"
where InvalidPath
does not exist on the object that's being bound... Is there a better way than relying on a magic-string path?