This is a migrated thread and some comments may be shown as answers.

RowNumColumn Alignment problem

1 Answer 33 Views
GridView
This is a migrated thread and some comments may be shown as answers.
suchan
Top achievements
Rank 1
suchan asked on 12 Jan 2016, 02:47 AM
Hi!
 
Recently I had a trouble as the following.
 
I did want a RowNumColumn with center horizontal alignment. so made it based on the post. (http://demos.telerik.com/silverlight/#GridView/RowNumber)
 
The Following line effect that if I scroll horizontal thumb slowly, left horizontal alignment column of GridView would be changed center alignment.
 
public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
  {
   TextBlock textBlock = cell.Content as TextBlock;
 
   if (textBlock == null)
   {
    textBlock = new TextBlock();
    //The Following line effect that
    //if you scroll horizontal thumb slowly, left horizontal alignment column of GridView would be converted center alignment.
    //. ex (RowNum, Center, Center, Center, Left ... )
    textBlock.HorizontalAlignment = HorizontalAlignment.Center;
   }
 
   textBlock.Text = String.Format("{0}", DataControl.Items.IndexOf(dataItem) + 1);
 
   return textBlock;
  }
 
Could I fix it or any walkarounds?
 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 14 Jan 2016, 12:46 PM
Hello Suchan,

Because the HorizontalAlignment is set directly in the CreateCellElement, due to UI virtualization, that same container is reused and so that HorizontalAlignment is passed to the other cells of the GridView when you scroll to them. You can find more information about UI virtualization in this helpful article.

I've attached a sample project providing a simple solution to your scenario. I've removed the HorizontalAlignment from the CreateCellElement method and created a custom style where I've set the HorizontalAlignment of the cell to Stretch, the HorizontalContentAlignment to Center and set it as the custom column's CellStyle.

Please let me know if you find the provided project helpful and whether or not it solves your issue.

Regards,
Dilyan Traykov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
suchan
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or