BUG: Center DataGridCell Content in Silverlight

So I have been banging my head against a wall on this one. It appears that this is a bug. I am trying to apply a Horizontal Alignment of text within a given DataGridColumn’s cells. I am able to set the horizontal alginement on the Column Header to be Center but not on the individual elements.

<Style x:Key=”centeredCell” TargetType=”swcd:DataGridCell”>

<Setter Property=”HorizontalAlignment” Value=”Center” />

<Setter Property=”HorizontalContentAlignment” Value=”Center” />

<Setter Property=”TextAlignment” Value=”Center” />

</Style>

…and here is the column definition…

<swcd:DataGridTextBoxColumn DisplayMemberBinding=”{Binding ProductCode}” CellStyle=”{StaticResource centeredCell}”>

<swcd:DataGridTextBoxColumn.Header>

<HyperlinkButton Content=”Product” TextDecorations=”Underline” HorizontalAlignment=”Center” />

</swcd:DataGridTextBoxColumn.Header>

</swcd:DataGridTextBoxColumn>

This seems like it should not be difficult.

Anybody else having any luck with this?

UPDATE: There is a workaround. You can create your own Cell Template for each column, but who wants to do that honestly? 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s