Created
March 4, 2014 19:51
-
-
Save owen2/9354215 to your computer and use it in GitHub Desktop.
DataGridBoundTemplateColumn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks adam and merek