如何设置GridView分隔符的背景颜色? [英] How do I set the background color of GridView separators?

查看:61
本文介绍了如何设置GridView分隔符的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有五个列的GridView的ListView中显示了许多项目(仅文本).每行的背景色绑定到反映项目状态的颜色名称.像这样:

 <   ListView      名称  ="  viewInst" 
     填充  ="     ="   0,10,0,5"   
 
      Horizo​​ntalContentAlignment   ="    
      Horizo​​ntalAlignment   ="  
 
      ItemsSource   ="  > 

  <   ListView.View  > 
    <   GridView  > 
      <   GridView.Columns  > 

        <   GridViewColumn     ="  安装程序" 宽度  > 300"    > 
          <   GridViewColumn.CellTemplate  > 
            <   DataTemplate  > 
              <   TextBox     ="   200" 
                     span>               保证金   0" 填充  ="     ="span>  BorderThickness   ="  0" 
 
                     span>               背景   {Binding bgcol}" 
 
                     span>               文本   {Binding installerName}" / <  /DataTemplate  > 
         <  /GridViewColumn.CellTemplate  > 
      <  /GridViewColumn  >   pre> 

...,然后是另外四个类似的GridViewColumn定义.

我希望每个项目在表中显示为一行,但是在字段之间是列分隔符,用空格将行分开(或更确切地说:ListView的背景).

我已经搜索-尚未成功-将此列分隔符的宽度设置为零,或者(最好)将背景色设置为与行中单元格相同的颜色.请注意,为整个列分隔符设置(单一)背景色不是我想要的;颜色会逐行变化.

任何有关搜索内容以使行显示为行而不是一行分离的单元格的提示都将受到高度赞赏!

解决方案

我不是当然可以,但是请尝试

 <  数据模板 > ; 
    <  边框    ="   0,0,0,0"   背景  ="    画笔  ="  > 
        <  文本块    ="   2" 文本   {Binding installerName }" / <  /border  > 
<  /datatemplate  >   


I am presenting a number of items (text only) in a ListView with a GridView of five columns. The background color of each line is bound to a color name reflecting the state of the item. Like this:

<ListView  Name="viewInst"

  Padding="0" Margin="0,10,0,5" 

  HorizontalContentAlignment="Stretch" 

  HorizontalAlignment="Stretch"

  ItemsSource="{Binding guiInstSet}">

  <ListView.View>
    <GridView>
      <GridView.Columns>

        <GridViewColumn Header="Installer" Width="300" >
          <GridViewColumn.CellTemplate>
            <DataTemplate>
              <TextBox Width="200"

                Margin="0" Padding="0,2" BorderThickness="0" 

                Background="{Binding bgcol}" 

                Text="{Binding installerName}" />
            </DataTemplate>
         </GridViewColumn.CellTemplate>
      </GridViewColumn>



... followed by four more similar GridViewColumn definitions.

I would like each item to appear as one line in the table, but between the fields are the column separators, breaking up the line with white space (or rather: The Background of the ListView).

I have searched - with no success yet - for either ways to set the width of this column separator to zero, or (preferably) to set the background color to the same color as the cells on the line. Note that setting a (single) background color for the entire column separator is not what I want; the color changes from line to line.

Any hint about what to search for to make the lines appear as lines, rather than a row of disjunct cells, will be highly appreciated!

解决方案

I''m not sure, but try this

<datatemplate>
    <border borderthickness="0,0,0,0" background="{Binding bgcol}" borderbrush="{Binding bgcol}">
        <textblock margin="2" text="{Binding installerName}" />
    </border>
</datatemplate>


这篇关于如何设置GridView分隔符的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆