Interaction.Triggers在MVVM列表框视图中失败

时间:2012-01-18 20:13:16

标签: wpf xaml mvvm

当我在列表框的背景上的任何位置单击(MouseDown)时,下面的xaml可以正常工作。问题是,当我点击列表框中的任何一个项目时,我无法使其工作。我尝试将触发器代码放在边框,图像或TextBlock中但没有成功。

<ListBox Name="SelectL2List" ItemsSource="{Binding L2Items, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsSynchronizedWithCurrentItem="True">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDown">
            <si:CallDataMethod Method="HideSelectL2View" Target="{Binding}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel IsItemsHost="True" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate DataType="{x:Type ViewModels:MediaItemViewModel}" >
            <Border BorderThickness="1,1,3,3" Margin="10" CornerRadius="3">
                <StackPanel Orientation="Horizontal" >
                    <Image Source="{Binding Image}"/>
                        <TextBlock Text="{Binding L2Title}" />
                    </StackPanel>
                </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您必须确保所有内容都经过测试,您可以将边框的Background设置为Transparent以确保。{/ p>

ListBoxItems拦截鼠标事件,使用tunneling版本,即PreviewMouseDown