EventTocommand将项目单击在ItemScontrol中



这是我在xaml中的布局:

<ScrollViewer Name="svDesigner" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Focusable="False">
    <ItemsControl ItemsSource="{Binding DesignerRowsCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <ItemsControl.ItemTemplate>
            <DataTemplate DataType="{x:Type base:UI_DesignerRow}">
                <cntrl:BabDesignerRow Margin="2"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <dxmvvm:Interaction.Behaviors>
            <dxmvvm:EventToCommand EventName="MouseLeftButtonDown" 
                               Command="{Binding SetPropertiesSourceCommand}" PassEventArgsToCommand="True">
                <dxmvvm:EventToCommand.EventArgsConverter>
                    <conv:DesignerItemClickEventArgsConverter/>
                </dxmvvm:EventToCommand.EventArgsConverter>
            </dxmvvm:EventToCommand>
        </dxmvvm:Interaction.Behaviors>
    </ItemsControl>

在背后的代码中,我有此子处理scrollviewer的previewmouseleftbuttondown事件:

Private Sub DesignerItemSelectionRedirect(sender As Object, e As MouseButtonEventArgs) Handles svDesigner.PreviewMouseLeftButtonDown

在我的USERCONTROL BABDESIGNERROW内部,我有很多不同的UI对象,例如TextBox,Combobox,LayoutGroup等。

现在,无论我在哪里单击,我始终将整个itemscontrol作为e.source而不是选择的真实对象。

有没有办法将对象单击在我的UserControl内部?

我需要获取此信息,以突出显示用户选择的内容。

这是因为路由事件的隧道策略。您应该阅读有关路由事件及其起泡和隧道策略的更多信息。

您可以使用此事件的类似起泡的版本:MouseLeftButtonDown。如MSDN所述:

虽然这似乎遵循通过元素冒泡的路线 树,这实际上是一个直接的路由事件 沿每个uielement沿元素树。

所以这不是一个真正冒泡的事件,但应该适合您的情况。

另外,您可以使用e.OriginalSource属性而不是e.Source来获取引起此事件的元素。

最新更新