I have a custom class called TextBoxColumn as Follows
public class TextBoxColumn : DataGridTemplateColumn { public static readonly DependencyProperty FieldNameProperty = DependencyProperty.Register("FieldName", typeof(string), typeof(TextBoxColumn), new PropertyMetadata("")); public string FieldName { get { return (string)GetValue(FieldNameProperty); } set { SetValue(FieldNameProperty, value); } } } When creating DataGrid columns from XAML:
<DataGrid> <DataGrid.Columns> <local:TextBoxControl FieldName="FirstName"/> <local:TextBoxControl FieldName="LastName"/> </DataGrid.Columns> </DataGrid> In XAML Dictionary, I have defined the Cell Template for this TextBoxColumn:
<DataTemplate x:Key="TextBoxColumn_CellTemplate"> <TextBox Text="{Binding FieldName}"/> <!-- Here is the problem, if I give FirstName instead of FieldName, it works fine --> </DataTemplate>` How to get the value of FieldName property of TextBoxColumn and Bind it to Text property? How can I achieve it without C# code?
DataGridTextColumn?