This question is locked. New answers and comments are not allowed.
I want to do the same thing as described in http://www.telerik.com/forums/binding-to-a-dictionary, except I am using the DataGrid from UI for Windows Universal instead of UI for Silverlight.
I created a DictionaryConverter that derives from IValueConverter just as the solution in the post I linked above describes. However, when I get to build/bind the columns, I run into issues.
In the Silverlight version, the solution included an approach like:
However, in the Windows Universal version, I do not have a GridViewDataColumn class available. Instead, I am trying to use a DataGridTextColumn. The problem is that DataGridTextColumn does not support a DataMemberBinding property which the solution above depends on. The only way I can see of telling DataGridTextColumn which property to bind to in my row object is by assigning the PropertyName attribute. This won't work because I don't have named properties on my row objects - I'm binding to keys in a Dictionary. Is there any way to achieve this?
I created a DictionaryConverter that derives from IValueConverter just as the solution in the post I linked above describes. However, when I get to build/bind the columns, I run into issues.
In the Silverlight version, the solution included an approach like:
private
void
BuildColumns(Layer layer)
{
for
(
int
i = 0; i < layer.Data[0].Attributes.Count; i++)
{
string
key = layer.Data[0].Attributes.Keys.ElementAt(i);
GridViewDataColumn dataColumn =
new
GridViewDataColumn();
dataColumn.HeaderText = key;
dataColumn.DataMemberBinding = PrepareDataMemberBinding(key);
this
.testGridView.Columns.Add(dataColumn);
}
}
private
System.Windows.Data.Binding PrepareDataMemberBinding(
string
key)
{
Binding binding =
new
Binding();
binding.Path =
new
PropertyPath(
"Attributes"
);
binding.Converter =
new
DictionaryConverter(key);
return
binding;
}
public
class
Layer
{
public
List<LayerData> Data {
get
;
set
; }
}
public
class
LayerData
{
public
Dictionary<
string
,
object
> Attributes {
get
;
set
; }
}
However, in the Windows Universal version, I do not have a GridViewDataColumn class available. Instead, I am trying to use a DataGridTextColumn. The problem is that DataGridTextColumn does not support a DataMemberBinding property which the solution above depends on. The only way I can see of telling DataGridTextColumn which property to bind to in my row object is by assigning the PropertyName attribute. This won't work because I don't have named properties on my row objects - I'm binding to keys in a Dictionary. Is there any way to achieve this?