<GridViewColumn Header="列名称1" > <GridViewColumn.CellTemplate> <DataTemplate> <Border BorderBrush="LightBlue" BorderThickness="1,0,0,0" Padding="0" Margin="-9,0,0,0"> <Label Content="{Binding Path=Name}" MinWidth="80" HorizontalContentAlignment="Center" /> </Border> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn>
<GridViewColumn Header="列名称2"> <GridViewColumn.CellTemplate> <DataTemplate> <Border BorderBrush="LightBlue" BorderThickness="1,0,0,0" Padding="0" Margin="-9,0,0,0"> <Label Content="{Binding Path=Age}" MinWidth="80" HorizontalContentAlignment="Center" /> </Border> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn>
如果列数较多的话,
DataTemplate肯定重复的也比较多。不同之处就是绑定的值。我想把celltemplate提取出来。
例如:
<GridViewColumn Header="列名称2" CellTemplate="{StaticResource celltemplate}" DisplayMemberBinding="{Binding Age}" > </GridViewColumn> <DataTemplate x:Name="celltemplate"> <Border BorderBrush="LightBlue" BorderThickness="1,0,0,0" Padding="0" Margin="-9,0,0,0"> <Label Content="{Binding Path=??????}" MinWidth="80" HorizontalContentAlignment="Center" /> </Border> </DataTemplate>
但是我不知道datatemplate里面的lablel content怎么绑定该列的值呢?
貌似提不出来的呦~~