I was trying to bind my DataGrid columns to a list where the item for a column could be retrieved using an indexer. The indexer type is DateTime.
I am creating the DataGrid columns using code and wanted to create a binding to retrieve the value from the list. In XAML the path would be written as:
{ Binding Path=Values[01/01/2011] }
But since I am doing it in code behind I need to define the path using a PropertyPath, like so:
new Binding{
Path = new PropertyPath("Values[01/01/2011]")
}
There is another overload for the constructor that takes a path and an array of parameters. According to the documentation the parameters are used for indexers. But when I write my binding as
new Binding {
Path = new PropertyPath("Values", new DateTime(2011, 01, 01))
}
the binding cannot resolve the path. Fair enough, I'm not stating that it should look for an indexer. But if I write it as:
new Binding{ Path = new PropertyPath("Values[]", new DateTime(2011, 01, 01)) }
then DateTime.MinValue is passed to the indexer.
Can someone explain to me how I use the PathParameters in the constructor and how I can bind to indexers without having to do a ToString on my value in the actual path?