【问题标题】:How can I get rid of the rounded corners on the ListViewItem in a WPF listview?如何摆脱 WPF 列表视图中 ListViewItem 上的圆角?
【发布时间】:2011-06-07 04:55:48
【问题描述】:

我有一个样式应用于 Listview 的 ItemContainerStyle。它在行的底部放置一条线并设置行的高度。

但是由于某种原因 - 每行似乎都有圆角(如所附快照所示)。当我查看 Blend 中的样式时 - 没有圆角。

如何去除圆角?

<Style TargetType="ListViewItem" x:Key="RowStyle">
                <Setter Property="BorderThickness" Value="0,0,0,1" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonPressedColor}" />
                <Setter Property="Height" Value="40" />
                <Setter Property="Background" Value="#FFF9EDED"/>

            </Style>            

        <ListView x:Name="lvw_FileList" Background="{DynamicResource Watermark}" ItemContainerStyle="{StaticResource RowStyle}" BorderBrush="{DynamicResource GreyBorderColor}" BorderThickness="3" Margin="0" ItemsSource="{Binding Mode=OneWay}" d:DataContext="{d:DesignData /SampleData/SampleListItems.xaml}" Foreground="{DynamicResource TextColor}">    
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <GridView.ColumnHeaderContainerStyle>
                        <Style>
                            <Setter Property="UIElement.Visibility" Value="Collapsed" />
                        </Style>
                    </GridView.ColumnHeaderContainerStyle>                  
                    <GridViewColumn Header="Picture" CellTemplate="{DynamicResource PictureCell}" />
                    <GridViewColumn Header="Name" CellTemplate="{DynamicResource CompanyNameCell}" />                   
                    <GridViewColumn Header="Action" CellTemplate="{DynamicResource ActionCell}" />
                    <!--<GridViewColumn Header="Delete" Width="50"/>-->
                </GridView>
            </ListView.View>            
        </ListView>

【问题讨论】:

    标签: wpf xaml styling listviewitem


    【解决方案1】:

    Round conrner 是因为这条线。您已将厚度 1 分配给底部

    <Setter Property="BorderThickness" Value="0,0,0,1" />
    

    把这个改成

     <Setter Property="BorderThickness" Value="0,0,0,0" />
    

    【讨论】:

    • 我明白了——所以底层模板有一个设置了圆角半径的边框对象——一旦我创建了一个边框,它就会继承这个属性。要修复它,我需要为 ListItemView 创建一个模板?
    • 默认是否可以验证控件模板中的默认ListviewItemStyle Contentpresenter是用Border包裹的,而Thickness是使用Templatebinding继承的
    • 如果您需要自定义行样式,您可以创建自己的 ListviewItem 样式
    【解决方案2】:

    我认为这与 ListView 的样式无关,而是与 ListView 内的 GridViewColumn 的样式有关。因为缺少那种风格。

    您可以发布您的示例数据 xml 吗?

    【讨论】:

      猜你喜欢
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 2010-11-09
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      相关资源
      最近更新 更多