2

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?

1
  • Why not use a DataGridTextColumn? Commented Sep 6, 2012 at 8:12

2 Answers 2

1

Give a name to TextBoxColumn control and try to bind it's property by element name

<TextBox Text="{Binding ElementName=txtBoxCol, Path=FieldName}"></TextBox> 
Sign up to request clarification or add additional context in comments.

1 Comment

It is showing the value of the FieldName for that TextBoxControl e.g. FirstName, LastName etc, not binding with FirstName or LastName (the value of FieldName)
0

You cannot do thing without code, there is no way to bind properties of a binding (in this case you would want Binding.Path to be whatever the FieldName is).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.