0

我有一组视图,我希望能够在视图上调用一个方法来响应 ViewModel 中引发的事件。

我目前正在使用带有 DataTemplate 的 ItemsControl ,但这并没有让我有机会拦截 View 和 ViewModel 并将它们连接起来。有没有更适合这个的容器?

4

1 回答 1

1

从:

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"   

用户:源对象是您的 ViewModel。

   <UserControl>
        <i:Interaction.Triggers>
            <i:EventTrigger SourceObject="{Binding}" EventName="YourEvent">
                <ei:CallMethodAction MethodName="YourMethod"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </UserControl>

如果您将它放在另一个元素的范围内,那么您的视图(用户控件)添加

 <ei:CallMethodAction MethodName="YourMethod" TargetObject="{Binding ElementName=yourUserControl}"/> 
于 2013-10-31T12:44:52.743 回答