您应该考虑将Userlist.xaml中的用户列表绑定到ProfileViewModel实例的集合,然后您可以将特定的ProfileViewModel提供给profile.xaml。
在这个例子中,你Userlist.xaml将包括:
<UserControl Name="userView">
<!-- other stuff -->
<ItemsControl ItemsSource={Binding Users}>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding UserName}" />
<Button Content="View User Profile"
Command="{Binding ElementName=userView, Path=DataContext.ViewUserProfileCommand}"
CommandParameter="{Binding}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- other stuff -->
</UserControl>
和你UserlistViewModel将包括:
#region Users Property
public const string UsersPropertyName = "Users";
private ObservableCollection<IProfileViewModelViewModel> _users;
public ObservableCollection<IProfileViewModelViewModel> Users
{
get { return _users; }
set
{
if (_users == value)
return;
_users = value;
RaisePropertyChanged(UsersPropertyName);
}
}
#endregion
public RelayCommand<IProfileViewModel> ViewUserProfileCommand
= new RelayCommand<IProfileViewModel>(ViewUserProfileCommandExecute);
private void ViewUserProfileCommandExecute(IUserProfileViewModel userProfileViewModel)
{
// display your profile view here
}
芦苇上面提到的,用户配置文件的视图模型传递到一个方法您的其他页面将是MVVM Light Toolkit's messaging。