0

我是 MVVMLight 的新手。我想在全景标签更改后调用一些方法。我想了解有关所选全景选项卡的信息。一个问题是,未调用 HandlePanoramaViewSelected 方法。

我不能让它工作。不知道怎么回事

xml:

<controls:Panorama x:Name="mainViewPanorama">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <cmd:EventToCommand Command ="{Binding PanoramaSelectedViewCommand, Mode=OneWay}"
                                        CommandParameter="{Binding SelectedValue, ElementName=mainViewPanorama}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
</controls:Panorama>

构造函数:

PanoramaSelectedViewCommand = new RelayCommand<SelectionChangedEventArgs>(x => HandlePanoramaViewSelected(x));

视图模型:

public RelayCommand<SelectionChangedEventArgs> PanoramaSelectedViewCommand { get; set; }

private void HandlePanoramaViewSelected(SelectionChangedEventArgs args)
{
// do something
}
4

1 回答 1

1

您正在混合两种不同的方法。请仅执行以下示例之一:

传递事件参数

XAML:

<controls:Panorama x:Name="mainViewPanorama">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <cmd:EventToCommand Command ="{Binding PanoramaSelectedViewCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</controls:Panorama>

属性和处理程序:

public RelayCommand<SelectionChangedEventArgs> PanoramaSelectedViewCommand { get; set; }

private void HandlePanoramaViewSelected(SelectionChangedEventArgs args)
{
    // do something
}

构造函数:

PanoramaSelectedViewCommand = new RelayCommand<SelectionChangedEventArgs>(HandlePanoramaViewSelected);



传递命令参数

XAML:

<controls:Panorama x:Name="mainViewPanorama">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <cmd:EventToCommand Command ="{Binding PanoramaSelectedViewCommand}"
                                CommandParameter="{Binding Path=SelectedItem, ElementName=mainViewPanorama}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</controls:Panorama>

属性和处理程序:

public RelayCommand<object> PanoramaSelectedViewCommand { get; set; }

private void HandlePanoramaViewSelected(object selectedItem)
{
    // do something
}

构造函数:

PanoramaSelectedViewCommand = new RelayCommand<object>(HandlePanoramaViewSelected);
于 2012-10-23T17:44:35.613 回答