I recently started using WPF Datagrid with a DataGridTemplateColumns containing WPF AutoCompleteBox, but I found problems implementing the Clipboard.Paste function for these DataGridTemplateColumns.
I managed to load Clipboard.Paste with embedded DataGridColumns through the Vishal guide here , but this does not work with DataGridTemplateColumns.
Returning to the OnPastingCellClipboardContent method in the DataGridColumn class, it seems that fe.GetBindingExpression (CellValueProperty) returns zero, not the required BindingExpression.
Can someone point me in the right direction?
public virtual void OnPastingCellClipboardContent(object item, object cellContent)
{
BindingBase binding = ClipboardContentBinding;
if (binding != null)
{
if (PastingCellClipboardContent != null)
{
DataGridCellClipboardEventArgs args = new DataGridCellClipboardEventArgs(item, this, cellContent);
PastingCellClipboardContent(this, args);
cellContent = args.Content;
}
if (cellContent != null)
{
FrameworkElement fe = new FrameworkElement();
fe.DataContext = item;
fe.SetBinding(CellValueProperty, binding);
fe.SetValue(CellValueProperty, cellContent);
BindingExpression be = fe.GetBindingExpression(CellValueProperty);
be.UpdateSource();
}
}
Thank!