简体   繁体   English

如何在ListView下的Gridview中设置单元格的样式

[英]How to Style a cell in Gridview under ListView

How to style every cell in Gridview.I want my cell text in a rounded text box with red background.My code is 如何在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>

Use the GridViewColumn's CellTemplate property to set a DataTemplate containing a TextBox with the appropriate styling for each of your columns. 使用GridViewColumn的CellTemplate属性来设置一个DataTemplate,该DataTemplate包含一个TextBox,该TextBox的每个列均具有适当的样式。 I don't believe there is a way to set it at the Gridview level so that you don't have to set it on each column individually. 我不相信有一种方法可以在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM