2

如何在 Gridview 中设置每个单元格的样式。我希望我的单元格文本位于红色背景的圆形文本框中。我的代码是

<ListView Margin="0"  ItemsSource="{Binding ParamList}" >
    <ListView.View >
        <GridView  >
            <GridView.ColumnHeaderTemplate>
                <DataTemplate>
                    <Border  BorderThickness="2" CornerRadius="5" Height="75" MinWidth="60"  >
                        <Border.Background>Gray</Border.Background>
                        <TextBlock Foreground="WhiteSmoke" Margin="5" 
                                   Text="{Binding}" Width="Auto" 
                                   HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Border>
                </DataTemplate>
            </GridView.ColumnHeaderTemplate>

            <GridViewColumn Header="category1" DisplayMemberBinding="{Binding Path=param1}"   />
            <GridViewColumn Header="category2" DisplayMemberBinding="{Binding Path=param1}" />

        </GridView>
    </ListView.View>
</ListView>
4

1 回答 1

1

使用 GridViewColumn 的 CellTemplate 属性来设置一个 DataTemplate,该 DataTemplate 包含一个 TextBox,并为您的每一列提供适当的样式。我不相信有办法在 Gridview 级别设置它,这样您就不必在每一列上单独设置它。

 <Grid>
    <ListView ItemsSource="{Binding Items}">
        <ListView.View>
            <GridView>
                <GridView.Columns>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Background="Red" Text="{Binding Item1}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Item2}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>
于 2013-08-22T05:27:04.120 回答