Skip to content

Instantly share code, notes, and snippets.

@owen2
Created March 4, 2014 19:51
Show Gist options
  • Save owen2/9354215 to your computer and use it in GitHub Desktop.
Save owen2/9354215 to your computer and use it in GitHub Desktop.
DataGridBoundTemplateColumn
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace OwensWpfFunStuff
{
public class DataGridBoundTemplateColumn : DataGridBoundColumn
{
public DataTemplate CellTemplate { get; set; }
public DataTemplate CellEditingTemplate { get; set; }
protected override System.Windows.FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
{
return Generate(dataItem, CellEditingTemplate);
}
private FrameworkElement Generate(object dataItem, DataTemplate template)
{
var contentControl = new ContentControl { ContentTemplate = template, Content = dataItem };
BindingOperations.SetBinding(contentControl, ContentControl.ContentProperty, Binding);
return contentControl;
}
protected override System.Windows.FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
{
return Generate(dataItem, CellTemplate);
}
}
}
@owen2
Copy link
Author

owen2 commented Mar 4, 2014

thanks adam and merek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment