Hello,
I have a question regarding your XamGrid for Silverlight 4.0.
Currently, I'm using the Standard DataGrid from Silverlight Tools and would like to use your XamGrid. However, I don't know how to use specific Binding objects for additional DataColumns that are created and added to the DataGrid after an ItemSource has been set.
The code for the Standard Silverlight DataGrid looks like this:
XAML
<sdk:DataGrid AutoGenerateColumns="True" Height="100" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="DetailsGrid" />
C#
...
DetailsGrid.ItemsSource = someGraphicsInAList;
Graphic oneGraphic = SelectedGraphics.First<Graphic>();
foreach (KeyValuePair<string, object> kvp in oneGraphic.Attributes)
{
DataGridTextColumn column = new DataGridTextColumn();
column.Header = kvp.Key;
column.Binding = new System.Windows.Data.Binding();
column.Binding.Mode = BindingMode.OneWay;
GraphicAttributesConverter oGraphicAttributesConverter = new GraphicAttributesConverter();
column.Binding.Converter = oGraphicAttributesConverter;
column.Binding.ConverterParameter = kvp.Key;
DetailsGrid.Columns.Add(column);
}
public class GraphicAttributesConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
return ((Graphic)value).Attributes[parameter.ToString()];
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
throw new NotImplementedException();
How Do I do this with the XamGrid?Thanks,Dennis
Thanks,
but this does not solve my problem. Maybe we go one step back:
I have a List of Dictionaries: List<Dictionary<string, object>>
Each Dictionary in the List has the same Keys. These keys should become the Columns. The Dictionaries values should become the values in the Grid.How can i bind my List of Dictionaries to the Grid?
And i do not know the Lists length and the Dictionaries length & keys at design time.
Thanks,Dennis
Hi,
As far as I can see from your code, you are just adding a text column with a converter. To get the same result with XamGrid you can use the following code snippet:
using Infragistics.Controls.Grids; ... TextColumn textColumn = new TextColumn { Key = columnKey }; textColumn.ValueConverter = new YourValueConverter(); textColumn.ValueConverterParameter = parameter; this.xamGrid.Columns.Add(textColumn); ...
If you want to add a TemplateColumn at run-time you can look at this thread for more information.
Hope this helps