I have a WPF DataGrid templatecolumn that has a DataTemplate for an AutoCompleteBox from the wpf toolkit. During RowEditEnding event and validation procedures, I am not able to see the content in the templatecolumn.
<DataGridTemplateColumn Header="Account Type" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<toolkit:AutoCompleteBox Text="{Binding Path='Account Type'}" Populating="PopulateAccountTypesACB" IsTextCompletionEnabled="True" BorderThickness="0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
if ((value as BindingGroup).Items.Count == 0)
return new ValidationResult(true, null);
DataRowView row = (value as BindingGroup).Items[0] as DataRowView;
if (row != null)
{
if (ValidateAccountName(row.Row.ItemArray[0].ToString()))
{
return new ValidationResult(true, null);
}
else
{
return new ValidationResult(false,
"Account Name must be between 1 and 100 Characters.");
}
}
else
return new ValidationResult(true, null);
}
When I put a break point in my validation function after I create the DataRowView, the template column is empty. How would I get its content?
After looking into this, it seems like it doesn’t have anything to do with the DataGridTemplateColumn, but rather with the AutoCompleteBox from the Wpf Toolkit. The AutoCompleteBox has been nothing but trouble for me ever since I started using it. As a result, I decided to scrap it and use an Editable ComboBox instead. The combobox is much cleaner and more simple to implement. Here is how my code now looks and the datarowview is able to see what the user types in the box:
Code Behind (this.Types is an observable collection of strings)