Reputation: 263
This is probably a very stupid problem, which is also probably why I can't find an answer to it.
I have a datagrid in which I add messages every once in a while during a lengthy operation, and for some reason the textblocks appear slightly a bit on the right of the left border of the datagrid, even though there is no margin on the textblock and no padding on the datagrid :
Here is my XAML :
<DataGrid x:Name="dgrdMessages" HorizontalAlignment="Left" Margin="21,212,0,0" VerticalAlignment="Top" Height="202" Width="690">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Message" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Message}" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding IsError}" Value="true">
<Setter Property="TextElement.Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Any ideas ?
Upvotes: 0
Views: 191
Reputation: 2072
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>
</DataGridTemplateColumn.CellStyle>
Upvotes: 0
Reputation: 868
From your screenshot it does not seems the TextBlock are "slightly on the right" (they touch the left border). Do you want to get rid of the "row selector", the small gray button on the left? If so set HeadersVisibility="Column" in XAML.
Upvotes: 1