Hi IGTeam,
I am in a need to dynamically create columns for my igGrid;
I bind to data from my ViewModel, which is of type ObservableCollection<DynamicObject>;
Just before the binding, I want to create columns on the View side like this:
1. Create collection of TemplateColumn
2. Send to View
3. Simply add columns to grid
____________________________________________________________________
1. Iteration in for block (populate _dynamicGridColumnKeys)
TemplateColumn column = new TemplateColumn(); column.HeaderText = presentingName; column.ItemTemplate = (System.Windows.DataTemplate)System.Windows.Markup.XamlReader.Load(CreateColumnTemplate(propertyName)); //display template
private string CreateColumnTemplate(string propertyName) { StringBuilder CellTemp = new StringBuilder(); CellTemp.Append("<DataTemplate "); CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/"); CellTemp.Append("2006/xaml/presentation' "); CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>"); CellTemp.AppendFormat("<TextBlock Text='{{Binding [{0}]}}'/>", propertyName); CellTemp.Append("</DataTemplate>"); return CellTemp.ToString(); }
2.
Messenger.Default.Send<List<TemplateColumn>>(_dynamicGridColumnKeys, Preferences.CurrentGridName);
3.
Messenger.Default.Register<List<TemplateColumn>>(this, GridName, p => { foreach (var item in p) { this.customGrid.Columns.Add(item); } });
Can you please tell me why this works in System.Windows.Controls.DataGrid and I can't seem to fix it with the Infragistics one?
Please, this is important for me, I would appreciate if you inform me about this DynamicObject issue soon
Thanks
Hi,
Yes sorting and groupBy work out of the box with property indexers.
Filtering and summaries will work, however the property indexer needs to be typed. For example, your Dictionary should be someting like Dictionary<string, Foo>, not Dictionary<string, Object>
http://help.infragistics.com/NetAdvantage/Silverlight/2011/1/CLR4.0/?page=xamGrid_Support_for_String_Indexers.html
-SteveZ
Will sorting be supported with property indexers in the 10.3 release of the xamgrid?
Yes, that is exactly what I meant!
Since I am using 10.1 still, this is valuable information for me
Yes, it doesn't support DynamicObject binding, which means it won't resolve properties directly on your object.
You're talking about a workaround using indexer bindings. Which the xamGrid does support, as of the 10.3 release.
List<DynamicDataContext> data = new List<DynamicDataContext>();
for(int i = 0; i < 100; i++)
{
DynamicDataContext ddc = new DynamicDataContext();
ddc["Test"] = i;
data .Add(ddc);
}
grid.ItemsSource = data;
<ig:XamGrid.Columns>
<ig:TemplateColumn Key="[Test]">
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding [Test]}"/>
</DataTemplate>
</ig:TemplateColumn.ItemTemplate>
</ig:TemplateColumn>
</ig:XamGrid.Columns>
Hi Stephen,
Please don't mind me asking, but are you sure about that?
http://www.xavierdecoster.com/post/2010/10/08/Silverlight-4-Data-Binding-to-Dynamic-DataContext.aspx
This is more or less the way I got this 'unsupported' binding to work with my silverlight datagrid;
But anyways, that means that igGrid doesn't have this functionality, right?!