我有一个主题列表,每个主题都有一些示例。What I want to be able to do is that when a topic is selected then I will populate another view with all Examples for that selected topic. 我还在学习 MVVM,所以不知道如何实现。
EDIT: What I am attempting to do is to have two separate views (1 for the topics and 1 for the examples), and when an a topic is selected then I will 'dynamically' populate the collection of the examples and show them in the示例视图的列表框。
这就是我到目前为止所拥有的,我的想法是将示例的 ViewModel 传递给 TopicViewModel,但是如果两个视图都在主窗口的 XAML 中设置,我不确定该怎么做:
public TopicViewModel SelectedTopic
{
get { return _selectedTopic; }
set
{
_selectedTopic = value;
OnPropertyChanged("SelectedTopic");
//refresh list of exercises
if (_exampleViewModel != null)
{
_exampleViewModel.RefreshExercises(_selectedTopic.ID);
}
}
}