UserControl2.xaml 3.9 KB
<UserControl x:Class="SmartScan.SetControl.WPF.UserControl2"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:SmartScan.SetControl.WPF"
             mc:Ignorable="d" 
             d:DesignHeight="650" d:DesignWidth="500">
    <Grid>
        <ListView x:Name="data3" Background="#1c1c1c" BorderThickness="1" BorderBrush="Gray" Foreground="White" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="data3_SelectionChanged">
            <!-- 设置交替行数为2 -->
            <ListView.AlternationCount>2</ListView.AlternationCount>
            <!-- 自定义每个项的显示模板 -->
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ContentControl Content="{Binding Converter={StaticResource OcrTextHighlighter}}" 
       HorizontalAlignment="Stretch"
       VerticalAlignment="Center"  FontSize="14" FontFamily="微软雅黑"
       Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Converter={StaticResource WidthMinusMarginConverter}}"/>
                </DataTemplate>
            </ListView.ItemTemplate>

            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                    <Setter Property="VerticalContentAlignment" Value="Center"/>

                    <Setter Property="MinHeight" Value="25"/>
                    <Setter Property="Padding" Value="5,0"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListViewItem">
                                <Border x:Name="Border"
     Background="{TemplateBinding Background}"
     BorderThickness="0">
                                    <ContentPresenter HorizontalAlignment="Left" 
                   VerticalAlignment="Center"/>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter TargetName="Border" Property="Background" Value="#005A9E"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <!-- 交替行颜色 -->
                        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                            <Setter Property="Background" Value="#353535"/>
                        </Trigger>
                        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                            <Setter Property="Background" Value="#2a2a2a"/>
                        </Trigger>
                        <!-- 选中行颜色 -->
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="#0061c8"/>
                            <Setter Property="BorderBrush" Value="Transparent"/>
                        </Trigger>
                        <!-- 鼠标悬停效果 -->
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="#464646"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
    </Grid>
</UserControl>