I am developing a WPF application using MVVM pattern, in that application i have two comboboxes, i bind the itemssource of the comboboxes from a property of viewmodel, thoses properties are of type CollectionView class which implements ICollectionView interface. For tracking the current selected item. Because i need to update the second combobox items depending on the value of the selected item in the first combobox. This is a snapshot from the viewmodel class code:
public ICollectionView Projects { get; set; }
public ICollectionView Tasks { get; set; }
public ICollectionView Users { get; set; }
public NewTaskViewModel()
{
Projects = new CollectionView(this.GetProjects());
Projects.CurrentChanged += new EventHandler(projects_CurrentChanged);
Users = new CollectionView(this.GetProjectAssignedUsers());
}
void projects_CurrentChanged(object sender, EventArgs e)
{
Api.Project project = Projects.CurrentItem as Api.Project;
this.SelectedProjectId = project.Id;
this.Tasks = new CollectionView(this.GetTaskLists());
}
And this is the XAML part:
<ComboBox x:Name="textBox3" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding Path=Projects, Mode=TwoWay}" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True">
</ComboBox>
<ComboBox x:Name="textBox4" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding Path=Tasks}" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True">
</ComboBox>
What i am doing wrong because i don't get the second combo updated when i change the current selected item. I hope for a little help. cheers.