RowNumColumn Alignment problem

2 posts, 0 answers
  1. suchan
    suchan avatar
    2 posts
    Member since:
    Apr 2009

    Posted 11 Jan Link to this post

    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?
     
  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 14 Jan Link to this post

    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
  3. DevCraft banner
Back to Top