Wpf 网格和列定义
我在WPF应用程序中有一个网格。 我想显示网格中第一列上要向右对齐的所有文本块。 所以我想我可以这样定义和风格:Wpf 网格和列定义,wpf,grid,styles,Wpf,Grid,Styles,我在WPF应用程序中有一个网格。 我想显示网格中第一列上要向右对齐的所有文本块。 所以我想我可以这样定义和风格: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition> <ColumnDefinition.Resources> <Style TargetType={x:Type TextBlock}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition.Resources>
<Style TargetType={x:Type TextBlock}">
<Setter Property=....../>
</Style..
.....
这就是你想要的吗
<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>
您可能必须尝试使用PropertyTrigger,如下所示:
<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>
您是否让datagrid根据项目来源自动生成列?