I have a grid that is setup with template columns. The template columns have a TextBlock and I am setting the values of that TextBlock for some of the cells. When I scroll up and down the values are dissappearing or transposing.
Here is some of my code to show how i am setting things up and setting the textblock values:
I have a data template defined in the xaml file:
<DataTemplate x:Key="myCellTemplate" >
<TextBlock Text="" />
</DataTemplate>
Hi,
So, the code you're using isn't going to work, b/c as you scroll cells get recycled.
The following to help articles go into detail on how this works:
http://help.infragistics.com/Help/NetAdvantage/Silverlight/2009.1/CLR3.5/html/SL_xamWebGrid_Virtualization.html
http://help.infragistics.com/Help/NetAdvantage/Silverlight/2009.1/CLR3.5/html/SL_xamWebGrid_Control_the_Virtualization_Process.html
Essentially, you just set the value when the cell control gets scrolled into view.
If you want, you can loop through the rows, store the values on the Tag property of each cell, and use the CellControlAttached event, and load your textbox with the value in the tag of the cell.
Or, you can use a ValueCoverter and a binding on the TextBlock in your DataTemplate.
-SteveZ
Stephen Zaharuk said: If you want, you can loop through the rows, store the values on the Tag property of each cell, and use the CellControlAttached event, and load your textbox with the value in the tag of the cell.
This sounds like a perfect solution for what I am doing i was already storing enough info in the tag for another reason.
BUT I added: CellControlAttached="TaxonomyGrid_CellControlAttached"
To the XamWebGrid and whenever it gets called the Tag is null, even though the code that sets it has already ran????
Any thoughts? Thank you for your help so far.
The event would only fire when cells for those columns come into view.
Have you tried scrolling them into view, and validating that it gets triggered?
Also, make sure that the code you're using to set the tag of the cell is being hit. If your binding before the grid is loaded, you'd want to loop through your rows in the loaded event.
Also, i think you might want to try the ValueConverter approach with your TextBlock, as i think it could provide a cleaner solution.
I have a table with 3 fixed columns, A,B,and C, and a certain number of dynamic columns, all in view.I scroll verticially which brings in many new rows. The trigger fires for columns A,B, and C but none of the dynamic columns.I am not sure I can use the valueConverter approach since I am not binding to a data object that has values for these columns.
I made sure the code setting the tag is hit, but thats irrelevent at this point since the controlAttach event isn't even firing for these columns.
Thanks for all you help so far. here is the code i am using to create the column, am i potentially setting a field that is preventing the event from firing? var tc = new TemplateColumn();
tc.ItemTemplate = (DataTemplate)Resources["myCellTemplate"];
//var tc = (TemplateColumn)Resources["TemplateColumn"];
tc.HeaderText = currentDate.Value.ToString("ddd\nMM/dd");
tc.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
//tc.HeaderStyle = App.Current.Resources["HeaderCellControlStyle1"] as Style;
tc.CellStyle = Application.Current.Resources["RedStyle"] as Style;
tc.Key = "day" + count++;
tc.IsFilterable = false;
tc.IsSortable = false;
tc.IsResizable = false;
tc.IsGroupable = false;
//tc.IsGroupBy = false;
tc.IsMovable = false;
TaxonomyGrid.Columns.Add(tc);
I'm guessing that you're data for those columns, is calculated based off the data for the row, right?
In which case a ValueConverter should certainly work, you would simply have the value for the binding, be the entire data object for the row.
TextBlock Text="{Binding Converter={StaticResource MyConverter}}", note by not setting the path the source of the binding, gets set to its DataContext, which is the data for the row.
As for the event not being raised, i looked into the code, and there is a bug, where it only fires for TemplateColumns that are bound to data. I have logged an issue for it, and it should be fixed in our next ServiceRelease.
Thanks,
The Text for the cell is currently based of information that i store in the Tag.But the information stored in the tag is based off the ColumnKey and an id for the data of a row.When is the service release expected.If its soon I could probably wait if not i could try to switch to the ValueConverter
The next SR is expected to be towards the end of November.
But, I definitely think you can easily make the ValueConverter approach work.
Was this fixed in the november/december release?
I have version 9.2 and the CellControlAttached still does not get called for my template columns that are being dynamicially added.
thanks