我希望能够从DataGrid单元格复制文本。
- First possible solution could be setting
SelectionUnit
toCell
but that's not an option for me since I need to selectFullRow
- Second possible approach was to have
DataGridTemplateColumn
with readonlyTextBox
in it. But there is an issue with styles. My previous question: DatagridCell style overriden by TextBox style. I need really bright color for text in row, but really dark in selected row. Third is to set IsReadOnly="False" on DataGrid and provide
EditingElementStyle
forDataGridTextColumn
<Style x:Key="EditingStyle" TargetType="{x:Type TextBox}"> <Setter Property="IsReadOnly" Value="True"/> </Style> ... <DataGridTextColumn ... EditingElementStyle="{DynamicResource EditingStyle}"/>
But here comes a really terrible bug WPF Datagrid Text Column allows one character text enter when the internal text box is set to read only.
你知道有没有其他解决方案或变通方法吗?谢谢。
编辑
我注意到来自扩展WPF工具包的DataGrid
没有这个bug,但它似乎有不同的结构,我无法应用我的DataGrid
样式。
我发现,将只读的TextBox作为DataGridColumn的EditingElementStyle会带来进一步的问题。当使用单向绑定时,就不能将单元格设置为编辑状态。让用户覆盖DataGrid中显示的某些实体的ID是不可接受的。因此,它必须以某种方式是只读的,或至少是单向绑定。
目前我完全没有解决这个问题的方法。还有其他方法可以让用户在选择和突出显示行的同时从单元格复制吗?我有没有忽略其他解决方案?谢谢您的阅读。
ObservableCollection<Foo>
,并且列基于Foo
的属性。在 Column1 中是Foo.Property1
等等。 - Kapitán Mlíko