Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
415
Scrolling causing text to change
posted

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>

I have a loop that adds date columns as follow:
   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);
Then I have code that loops through each row and sets some of the cells:
    foreach (var row in TaxonomyGrid.Rows)
                {
                       for (int i = startCell; i <= endCell; ++i)
                        {
                            CellBase cell = row.Cells[i];
                       
                                if (cell.Control != null)
                                {
                                    var tb = cell.Control.Content as TextBlock;
                                    if (tb != null)
                                    {
                                        tb.Text = "";
                                        if (cellPercentagUsed < 100)
                                            tb.Text = cellPercentagUsed + "% ";
                                        if (count > 1)
                                            tb.Text += "(" + count + ")";
                                    }
                           
                    }
                }
any thoughts???????????

Parents
No Data
Reply
  • 40030
    Suggested Answer
    Offline posted

    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

Children