我是MVVMLight的新手。我想在更改全景标签后调用一些方法。我想了解有关所选全景标签的信息。问题是,不调用HandlePanoramaViewSelected方法。
我无法让它发挥作用。不知道出了什么问题
XAML:
<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
}
答案 0 :(得分: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);