<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?
10 Answers, 1 is accepted
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.
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 >>
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
>
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 >>
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.
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 >>
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 >>
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
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.
I also have an issue with RadGridView alignment to right. I programmatically add columns to the GridView,
and the result is always left align, even when the 4-th parm is TextAlignment.Right.
public void AddDgColumn(RadGridView grid, string header, string propertyName,
TextAlignment textAlignment = TextAlignment.Left,
string columnGroupName = null, string stringFormat = null,
EWidthSize eWidth = EWidthSize.NA, double minWidth = 0, double starWidth = 0,
bool isReadOnly = true, double width = 0
)
{ // https://www.telerik.com/forums/column-textalignment-isn-t-working
try
{
Binding binding = new Binding(propertyName);
binding.Mode = BindingMode.OneWay;
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
if (stringFormat != null)
binding.StringFormat = stringFormat;
GridViewDataColumn column = new GridViewDataColumn
{
Header = header,
ColumnGroupName = columnGroupName,
IsReadOnly = isReadOnly,
DataMemberBinding = binding,
TextAlignment = textAlignment
};
Bob Boritz as bboritz@parcoinc.com
In the provided code snippet the TextAlignment is set to Left. Setting it to Right is working as expected on my end. Attached to my reply you can find a sample application demonstrating this. Can you please take a look at it?
Regards,
Stefan
Progress Telerik