WPF Gridview的Listview悬停样式

时间:2018-10-17 07:41:17

标签: c# wpf xaml listview gridview

在WPF中,我需要对ListView中的GridView做一些事情。 我尝试了很多事情,但是有一个问题。当它悬停时,我无法设置样式。我不想使用默认的悬停样式。

像这样:

Like this

这是我的代码。

<ListView x:Name="OutgoLog" Margin="88,412,0,118" Width="596" FontSize="18" FontFamily="./Resources/#Arita-dotum(TTF)" Padding="-4,-2,-2,0" BorderThickness="0" Background="{x:Null}" BorderBrush="White" Foreground="Black" Focusable="False" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Left">
        <ListView.Template>
            <ControlTemplate>
                <Border CornerRadius="20" BorderThickness="2" BorderBrush="#88FFFFFF" Background="#88FFFFFF">
                    <StackPanel>
                        <ContentPresenter Content="{TemplateBinding BindingGroup}"></ContentPresenter>
                        <ItemsPresenter/>
                    </StackPanel>
                </Border>
            </ControlTemplate>
        </ListView.Template>
        <ListItem LineHeight="40"></ListItem>
        <ListView.View>
            <GridView>
                <GridView.ColumnHeaderContainerStyle>
                    <Style TargetType="GridViewColumnHeader">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="Transparent"/>
                            </Trigger>
                        </Style.Triggers>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                                    <Border BorderThickness="0,0,1,0" BorderBrush="#88FFFFFF" Background="Transparent">
                                        <Label x:Name="ContentHeader" Content="{TemplateBinding Content}" Padding="2,2,2,2" Foreground="Black" Width="{TemplateBinding Width}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="OverridesDefaultStyle" Value="True" />
                    </Style>
                </GridView.ColumnHeaderContainerStyle>
                <GridViewColumn Width="50">
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <Label Content="{Binding StudentNumber}" HorizontalContentAlignment="Center" Padding="0,0,0,0" Width="{Binding GridViewColumn.Width}" VerticalContentAlignment="Center" Foreground="White" FontFamily="./Resources/#Arita-dotum(TTF)" Margin="0"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    <GridViewColumnHeader Tag="studentNumber" Content="a" BorderBrush="White" Height="30" Background="{x:Null}" Padding="0" BorderThickness="1,2" Foreground="White" FontWeight="Medium"/>
                </GridViewColumn>
                <GridViewColumn Width="63">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding StudentName}" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontFamily="./Resources/#Arita-dotum(TTF)" Margin="0"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    <GridViewColumnHeader Tag="studentName" Content="b" BorderBrush="White" Height="30" Background="{x:Null}" Padding="0" BorderThickness="1,2" Foreground="White" FontWeight="Medium"/>
                </GridViewColumn>
                <GridViewColumn Width="151">
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <Label Content="{Binding OutAt}" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontFamily="./Resources/#Arita-dotum(TTF)" Margin="0"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    <GridViewColumnHeader Tag="outAt" Content="c" BorderBrush="White" Height="30" Background="{x:Null}" Padding="0" BorderThickness="1,2" Foreground="White" FontWeight="Medium"/>
                </GridViewColumn>
                <GridViewColumn Width="151">
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <Label Content="{Binding InAt}" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontFamily="./Resources/#Arita-dotum(TTF)" Margin="0"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    <GridViewColumnHeader Tag="inAt" Content="d" BorderBrush="White" Height="30" Background="{x:Null}" Padding="0" BorderThickness="1,2" Foreground="White" FontWeight="Medium"/>
                </GridViewColumn>
                <GridViewColumn Width="85">
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <Label Content="{Binding Duration}" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontFamily="./Resources/#Arita-dotum(TTF)" Margin="0"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    <GridViewColumnHeader Tag="duration" Content="e" BorderBrush="White" Height="30" Background="{x:Null}" Padding="0" BorderThickness="1,2" Foreground="White" FontWeight="Medium"/>
                </GridViewColumn>
                <GridViewColumn Width="94">
                    <GridViewColumn.CellTemplate >
                        <DataTemplate>
                            <Label Content="{Binding Status}" Padding="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="White" FontFamily="./Resources/#Arita-dotum(TTF)" Margin="0"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    <GridViewColumnHeader Tag="status" Content="f" BorderBrush="White" Height="30" Background="{x:Null}" Padding="0" BorderThickness="1,2" ClickMode="Hover" Foreground="White" FontWeight="Medium"/>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

我使用了ListView和内部GridView,实际上我并不了解它们,因此我在Stackoverflow中提到了许多其他问题。因此,这段代码效率不高,因此,如果有更好的方法,我会非常喜欢。

我不知道在哪里添加代码来编辑悬停样式。

0 个答案:

没有答案