I have a collection bound to Combobox and it's SelectedItem is bound to my viewmodel property SelectedItem
.
<ComboBox ItemsSource="{Binding itemSource}"
SelectedItem="{Binding SelectedItem}"/>
The class of SelectedItem
is as follows:
public class SelectedItem
{
public AnotherViewModel anotherViewModel {get;set;}
}
I have used an Usercontrol like below:
<local:usercontrol DataContext="{Binding SelectedItem.anotherViewModel}"/>
I am trying to change the content of usercontrol on selection change of combobox in main view.
The changes to properties of anotherViewModel
reflects to the view only first time.
On debugging the code, I found that properties of anotherViewModel
contains new values but it doesn't reflect to view.
Any help would be appreciated.
Edit
Public class MainViewModel
{
public string property1 {get;set;} //has propertychanged implemented
public ObservableCollection<Item> Items {get;set;} //combobox itemsource
public Item SelectedItem {get;set;}//combobox selecteditem
}
public class Item
{
public AnotherViewModel anotherViewModel {get;set;}//has propertychanged implemented
}
public class AnotherViewModel
{
public string property1 {get;set;} //has propertychanged implemented
public string property2 {get;set;} //has propertychanged implemented
public ObservableCollection<string> items {get;set;} //has propertychanged implemented
}
<Window>
<Textbox Text="{Binding property1}"/>
<ComboBox ItemsSource="{Binding Items}"
SelectedItem="{Binding SelectedItem}"/>
<local:usercontrol DataContext="{Binding SelectedItem.anotherViewModel}"/>
<Window>
<UserControl>
<ListView ItemsSource="{Binding items}"/>
</UserControl>