0

我有一个使用以下样式的带有垂直线的 WPF ListView:(对不起长度,但我认为我应该包括它)

    <SolidColorBrush x:Key="verticalLineColor" Color="Red" />
    <Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}">
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <DockPanel Margin="{TemplateBinding Padding}">
                            <ScrollViewer Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" DockPanel.Dock="Top">
                                <GridViewHeaderRowPresenter x:Name="viewHeaderRowPresenter"
                                        Margin="-2,0,-2,0"
                                        Columns="{Binding Path=TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}"
                                        ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}"
                                        ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                        ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"
                                        AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}"
                                        ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
                                        ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />


                            </ScrollViewer>

                            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"                                         
                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                        KeyboardNavigation.DirectionalNavigation="Local"
                                        CanContentScroll="{TemplateBinding CanContentScroll}">

                                <ScrollContentPresenter.Content>
                                    <Grid>
                                        <!-- Container of vertical and horizontal lines -->
                                        <ItemsControl Margin="-1,0,0,0" ItemsSource="{Binding Path=TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <Border Width="{Binding Path=ActualWidth}" BorderThickness="0,0,.5,0" BorderBrush="{DynamicResource verticalLineColor}" Opacity="1" />
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                            <ItemsControl.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <StackPanel Orientation="Horizontal" />
                                                </ItemsPanelTemplate>
                                            </ItemsControl.ItemsPanel>
                                        </ItemsControl>
                                        <ContentControl Content="{TemplateBinding Content}" />
                                    </Grid>
                                </ScrollContentPresenter.Content>
                            </ScrollContentPresenter>
                        </DockPanel>
                        <ScrollBar Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Cursor="Arrow" x:Name="PART_HorizontalScrollBar" Grid.Row="1" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0.0" Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Orientation="Horizontal" ViewportSize="{TemplateBinding ViewportWidth}"/>
                        <ScrollBar Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Cursor="Arrow" x:Name="PART_VerticalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0.0" Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Orientation="Vertical" ViewportSize="{TemplateBinding ViewportHeight}"/>
                        <DockPanel Grid.Column="1" Grid.Row="1" Background="{Binding Path=Background, ElementName=PART_VerticalScrollBar}" LastChildFill="false">
                            <Rectangle Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Width="1" Fill="White" DockPanel.Dock="Left"/>
                            <Rectangle Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Height="1" Fill="White" DockPanel.Dock="Top"/>
                        </DockPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

现在,这里一切正常。我现在遇到的问题是,如果我的字段之一为 0,我需要对 ListView 行之一进行遮蔽。我有以下代码可以让我完成 90% 的工作:

        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="VerticalContentAlignment" Value="Top" />
                <Setter Property="Foreground" Value="Black"/>
                <Setter Property="Margin" Value="0,-2,0,-1"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding QtyInBox}" Value="0">
                        <Setter Property="Background" Value="LightGray"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ListView.ItemContainerStyle>

现在,我遇到的问题是,当我设置背景时,它似乎“覆盖”了网格线。 在此处输入图像描述

有没有办法让这些垂直线显示出来?

编辑#1:好的,所以在玩了一会儿之后,我想知道这是否可行;在以下代码部分中:

<DataTemplate>
    <Border Width="{Binding Path=ActualWidth}" BorderThickness="0,0,.5,0" BorderBrush="{DynamicResource verticalLineColor}" />
</DataTemplate>

如果我能以某种方式连接到Background那里的房产,我应该能够让它工作。任何人都可以指出我在这里绑定的正确方向吗?我需要绑定到的字段QtyInBoxItemSourceListView 上。

编辑#2:看起来我错了;这似乎绑定了整个专栏;所以我不能在那里设置一行的背景。回到绘图板...

4

1 回答 1

0

不幸的是,我无法找到真正的解决方案。

我能做的最好的是将背景的透明度设置为 0.6 或 0.7。

不是一个完美的解决方案;因为它导致文本有点模糊,但现在已经足够了。

于 2012-06-29T19:43:55.733 回答