Column TextAlignment isn't working

9 posts, 0 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 31 Aug 2011 Link to this post

    Everything just aligns to the left.

                        <telerik:GridViewDataColumn  Header="Date" DataMemberBinding="{Binding EntDate, Converter={StaticResource NQtoDateTime}}" DataFormatString="{}{0:d}" TextAlignment="Right">

    I saw someone had a similar problem, and closed their IDE and it worked.  I'm using XP.  HeaderTextAlignment, or TextAlignment doesn't work on all of my girds now.  I know they used to work. I'm using internal builds .801 and .815 and .823 didn't work.  Maybe there's something I'm missing?

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Sep 2011 Link to this post

    Hello Dan,

    I have tested the case and both properties work as expected on my side. Please take a look at the sample and let me know in case of any misunderstanding. 


    Kind regards,
    Maya
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 01 Sep 2011 Link to this post

    Ok, I found out what was going on.  My default TextBlock style seems to over ride the Gridview column settings.

    I have a Styles.xaml I call with the following in it:
    <Style TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource BodyTextColorBrush}"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>
    Removing this from my style sheet makes HeaderTextAlignment="Right" and  TextAlignment="Right" work.  Is there a way around this?
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Sep 2011 Link to this post

    Hi Dan,

    You may define the Style you want to be applied for the particular RadGridView in its scope. For example:

      <UserControl.Resources>     
            <Style TargetType="TextBlock">         
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="FontFamily" Value="Georgia" />
                <Setter Property="HorizontalAlignment" Value="Left"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot"
              Background="White"
              DataContext="{StaticResource MyViewModel}">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
     
            <telerik:RadGridView Grid.Row="0"
                                 Name="clubsGrid"
                                 ItemsSource="{Binding Clubs}"
                                 AutoGenerateColumns="False"
                                 Margin="5">
                <telerik:RadGridView.Resources>
                    <Style TargetType="TextBlock">                 
                        <Setter Property="FontSize" Value="14"/>
                        <Setter Property="FontFamily" Value="Segoe UI" />
                        <Setter Property="HorizontalAlignment" Value="Right"/>
                        <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                </telerik:RadGridView.Resources>
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                                Header="Est."
                                                DataFormatString="{}{0:yyyy}"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
                                                Width="200"
                                                Header="Stadium"
                                                DataFormatString="{}{0:N0}"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
                     
    <TextBlock Text="My long looong text is here." Grid.Row="1" />        

    In this case the Style defined in RadGridView will be applied to all TextBlock-s in it, while the other Style will be applied to the TextBlock outside. 


    Greetings,
    Maya
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 02 Sep 2011 Link to this post

    Yeah, that will work, but I would think that HeaderTextAlignment and TextAlignment in the Grid Column should override what's in the default textblock style.
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Sep 2011 Link to this post

    Hello Dan,

    Indeed, you are quite right, setting the HederTextAlignment and TextAlignment properties of the column should override the values set through the style. Actually, we are in the process of investigating the issue. I will get back to you once we resolve it.

    Regards,
    Maya
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 24 Oct 2011 Link to this post

    Hello,

     You should use TextAlignment not HorizontalAlignment!

    All the best,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  9. Arnaud
    Arnaud avatar
    17 posts
    Member since:
    Mar 2013

    Posted 28 Apr 2015 Link to this post

    Hello,

    I'm facing the same issue. Setting TextAlignment="Right" in the column definition has no effect over the application wide predefined textblock style. I do not understand Vlad's answer, could you detail it ? 

    Arnaud

  10. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 30 Apr 2015 Link to this post

    Hello Arnaud,


    Currently the properties defined within the style will take precedence over the TextAlignment property defined for the column. 



    Regards,
    Vanya Pavlova
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner