I have ComboBox with "ProjectList":
MainWindow.xaml
<ComboBox ItemsSource="{Binding Path=ProjectList}" IsSynchronizedWithCurrentItem="True" />
Elements are adding inside below method and working ok:
MainViewModel.cs
[AddINotifyPropertyChangedInterface]
public class MainViewModel{
public ObservableCollection<string> ProjectList { get; internal set; }
= new ObservableCollection<string>();
public async Task GetProjects(){
...
foreach (AItem item in....)
{
ProjectList.Add(item.name)
}
}
}
Note - I have installed "PropertyChanged.Fody".
Now I have added second ComboBox "TaskList" to xaml:
<ComboBox ItemsSource="{Binding Path=TaskList}" IsSynchronizedWithCurrentItem="True" />
List here should be created based on selected item into "ProjectList". Method is mostly the same, only has a parameter:
public ObservableCollection<string> TaskList { get; internal set; }
= new ObservableCollection<string>();
public async Task GetTask(string projectId = ""){
...
foreach (AItem item in....)
{
TaskList.Add(item.name2)
}
}
Now I want to addopt this to my MVVM.
Problem is: when and how to run GetTask()? Instead of "internal set" for ObservableCollection TaskList should be implemented "onpropertychanged"?