I have a simple window with two comboboxes, which I want to automatically select a specific item in the view model.
Combobox1: Projects
Combobox2: Versions
When the first project is selected, I try to set the first version of that project.
public List<Project> Projects
{
get { return projects; }
set
{
Set(() => Projects, ref projects, value);
var bm1Project = projects.FirstOrDefault(project => project.Name.Equals("BM1"));
if (bm1Project != null)
{
SelectedProject = bm1Project;
}
}
}
private Project selectedProject;
public Project SelectedProject
{
get { return selectedProject; }
set
{
Set(() => SelectedProject, ref selectedProject, value);
Versions = selectedProject.Versions;
SelectedVersion = Versions.FirstOrDefault();
}
}
private Version selectedVersion;
public Version SelectedVersion
{
get { return selectedVersion; }
set
{
Set(() => SelectedVersion, ref selectedVersion, value);
SetIssues();
}
}
Just for reference, the xaml in the window
<TextBlock Text="Project:" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="0,0,10,0"/>
<ComboBox
Grid.Row="0" Grid.Column="1"
Width="120" Height="30"
ItemsSource="{Binding Projects}" SelectedItem="{Binding SelectedProject}" DisplayMemberPath="Name"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="Sprint:" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="0,0,10,0"/>
<ComboBox
Grid.Row="0" Grid.Column="3"
Width="120" Height="30"
ItemsSource="{Binding Versions}" SelectedItem="{Binding SelectedVersion}" DisplayMemberPath="Id"/>
While debugging I can see that the code is executed step by step. Still the Version ComboBox is not populated.
When I manually select the project, it works like a charm.
What am I doing wrong?
No comments:
Post a Comment