I have a combo box having four items.
If I select a first item then second combo box must show some item with respect to the selection of first combo box item . If I select the second item then the second combo box must show some item .
Please suggest some ideas.
Add 2 combo box in XAML file:
<ComboBox Name="cbTest1" SelectionChanged="cbTest1_SelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Center" Width="150" >
<ComboBoxItem Content="1"></ComboBoxItem>
<ComboBoxItem Content="2"></ComboBoxItem>
<ComboBoxItem Content="3"></ComboBoxItem>
<ComboBoxItem Content="4"></ComboBoxItem>
</ComboBox>
<ComboBox Name="cbTest2" ItemsSource="{Binding Data}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="150" />
In function cbTest1_SelectionChanged as per selected value you can set value in the variable data
private void cbTest1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
List<string> oData = new List<string>();
if (((ComboBoxItem)cbTest1.SelectedValue).Content.ToString() == "1")
{
oData.Add("DataType1_1");
oData.Add("DataType1_2");
oData.Add("DataType1_3");
oData.Add("DataType1_4");
}
else if (((ComboBoxItem)cbTest1.SelectedValue).Content.ToString() == "2")
{
oData.Add("DataType2_1");
oData.Add("DataType2_2");
oData.Add("DataType2_3");
oData.Add("DataType2_4");
}
viewModel.Data = oData;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.