ItemsControl问题上的事件

时间:2018-01-30 07:58:44

标签: wpf xaml events itemscontrol

我在网格中定义了ItemsControl,在ItemsControl.Resources中,我为子网格定义了2个事件, MouseEnter MouseLeave

<Grid>
<ItemsControl ItemsSource="{Binding Colonnes}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

    <ItemsControl.Resources>
        <Style TargetType="Grid" x:Key="StyleTableau">
            <EventSetter Event="MouseEnter" Handler="ColonneMouseEnter"/>
            <EventSetter Event="MouseLeave" Handler="ColonneMouseLeave"/>
        </Style>   
    </ItemsControl.Resources>

    <ItemsControl.ItemTemplate>
        <DataTemplate DataType="vm:VueModeleColonnePQ">
            <Grid Style="{StaticResource StyleTableau}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid Grid.Row="0" >
                    <Ellipse Style="{StaticResource StyleEllipseJ1}" Visibility="{Binding IsPionVisible, Converter={StaticResource boolConv}, ConverterParameter='visible.hidden'}"/>
                </Grid>

                <StackPanel Orientation="Vertical" Grid.Row="1" >
                    <Ellipse Style="{StaticResource StyleEllipseVide}" Name="El0"/>
                    <Ellipse Style="{StaticResource StyleEllipseVide}" Name="El1"/>
                    <Ellipse Style="{StaticResource StyleEllipseVide}" Name="El2"/>
                    <Ellipse Style="{StaticResource StyleEllipseVide}" Name="El3"/>
                    <Ellipse Style="{StaticResource StyleEllipseVide}" Name="El4"/>
                    <Ellipse Style="{StaticResource StyleEllipseVide}" Name="El5"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>                    
</ItemsControl>

我的问题是事件被触发,但当鼠标为每个椭圆输入和离开时,而不是父网格,我不知道为什么。

我哪里失败了?

谢谢。

0 个答案:

没有答案