Reputation: 3539
I am having a Grid in WPF application. I want to display all the text block on the first column in the grid to be aligned to the right. so I thought I could do it with ColumnDefinition and Style like this:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition.Resources>
<Style TargetType={x:Type TextBlock}">
<Setter Property=....../>
</Style..
.....
But This is is not working Any idea why?
Upvotes: 0
Views: 1407
Reputation: 10312
You may have to try a PropertyTrigger, something like the following :
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Grid.Column" Value="0">
<Setter Property="TextAlignment" Value="Right"/>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
Upvotes: 1
Reputation: 3674
Is that what you want?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Grid.Column" Value="0" />
<Setter Property="TextAlignment" Value="Right" />
</Style>
</Grid.Resources>
<TextBlock Text="foo" Grid.Row="0"/>
<TextBlock Text="bar" Grid.Row="1" />
</Grid>
Upvotes: 1