开发者

MouseEnter trigger fires inaccurately on items in ListBox

开发者 https://www.devze.com 2023-02-22 08:39 出处:网络
I\'m seeing a very odd problem in a WPF list box where the MouseEnter trigger for each item fires less accurately for items further down in my ListBox. My MouseEnter trigger fires off an animation tha

I'm seeing a very odd problem in a WPF list box where the MouseEnter trigger for each item fires less accurately for items further down in my ListBox. My MouseEnter trigger fires off an animation that increases the ScaleTransform of each item.

Example: I have a list box of 10 items. The list box is displaying the first 5 items. I hover over the first item and it scales fine. I hover over the 2nd item and I have to place the mouse a little further inside the list item control to see the effect. I hover over the third item and I have to place the mouse even further in. By the time I get to the last (5th) visible item in the list I 开发者_C百科have to place the mouse at about the mid-point of the control for the MouseEnter to fire. Then, I scroll down to the bottom to see items 6-10. Item #6 hovers just fine. #7 is less accurate, #8 even less accurate, and so on down to #10 which is very inaccurate.

Thus is looks like the vertical visible position in the list box affects the MouseEnter accuracy of each control.

EDIT: When I put this code in a clean XAML window it works fine. It must be some conflict outside of the code I have provided... I'll provide more details (or an answer) if I find something.

Any ideas on what might be causing this?

Here is my ListBox XAML:

<ListBox
    MaxHeight="530"
    ItemsSource="{Binding Appointments}"
    Background="Transparent"
    >
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <views:AppointmentControl DataContext="{Binding}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And here is what my AppointmentControl looks like:

<UserControl Height="155" Width="215">
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter">
            <BeginStoryboard>
                <Storyboard TargetProperty="RenderTransform.ScaleX">
                    <DoubleAnimation To="1.2" Duration="0:0:0.050" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave">
            <BeginStoryboard>
                <Storyboard TargetProperty="RenderTransform.ScaleX">
                    <DoubleAnimation To="1.0" Duration="0:0:0.050" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </UserControl.Triggers>

    <UserControl.RenderTransform>
        <ScaleTransform ScaleX="1.0" ScaleY="1.0"></ScaleTransform>
    </UserControl.RenderTransform>

    <Button
        Background="#FFCAEE7D" 
        BorderThickness="1,1,1,3" 
        Padding="0"
        >
        <StackPanel Height="125" Width="180">
            <TextBlock ... />
            <TextBlock ... />

            <ItemsControl>
                ...
            </ItemsControl>
        </StackPanel>
    </Button>
</UserControl>


What happens if you enter the ListBox starting with the fifth element? Do you still need to go halfway down to see the same effect?


The issue was that another control with a greater z-index on top of the list box was interfering with the list item hit testing. The other control had a supposedly transparent area but for whatever reason it interferes with the mouseenter. When I remove this other control the problem goes away.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号