绑定属性,属性的值我有一个名为TextBoxColumn自定义类如下如何在XAML
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); }
}
}
当从XAML创建的DataGrid列:
<DataGrid>
<DataGrid.Columns>
<local:TextBoxControl FieldName="FirstName"/>
<local:TextBoxControl FieldName="LastName"/>
</DataGrid.Columns>
</DataGrid>
在XAML字典,我已经定义此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>`
如何获取FieldName属性的值属性TextBoxColumn的y并将其绑定到Text属性?如何在没有C#代码的情况下实现它?
为什么不使用'DataGridTextColumn'财产? –