我有一个ListView&每个列表项在其中是一个包含图像的按钮。在单击按钮后,我试图导航到另一个页面(例如,page2.xaml),我正在使用MVVM light框架。
这是我的XAML:
<ListView Grid.Row="1" Grid.ColumnSpan="2"
Visibility="Visible"
ItemsSource="{Binding buttonLists}" >
<ListView.ItemTemplate>
<DataTemplate>
<Button Style="{StaticResource ImageButton}" Command="{Binding GoToCommand}">
<Grid Style="{StaticResource GridItem}" Background="Blue">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="{Binding imageSource}"></Image>
</Grid>
</Button>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
在我的ViewModel中,在我提供的类中,
public ICommand GoToCommand
{
get
{
return new RelayCommand(GoToCommand);
}
}
private readonly INavigationService gotoNavigationService;
private void GoToCommand()
{
}
应该在GoToCommand()中给出什么导航命令?我对RelayCommand不太熟悉。谢谢。
最后我找到了解决方案。荣誉
当我使用MVVM时,我必须包括这两个。
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
在类内部,我对方法进行了以下更改:
private void GoTo()
{
var navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
navigationService.NavigateTo<Page2>(null);
}
public ICommand GoToCommand
{
get
{
return new RelayCommand(GoTo);
}
}
- 有用。我可以导航到Page2.xaml
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句