I have a datagrid, which is filled by a datatable. Each entry in the table is an object of a custom type. For each cell I want to use an usercontrol to show the content. I use XamlReader to create the usercontrol in code behind.
I learned that the DataContext of the DataTemplate for the columns CellTemplate is a DataGridRow and I could access an element with the following code:
$@"<DataTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<TextBox Text=""{{Binding [{count}].Amount}}"" />
</DataTemplate>"
When I try the same with my usercontrol it fails:
$@"<DataTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<local:MyControl
MyProperty=""{{Binding [{count}]}}""
xmlns:local=""...
with the error:
BindingExpression path error: '[]' property not found on 'object'
Is the DataContext different when I use custom control? I don't get it...