A ComboBox
can be programmatically opened by setting the property IsDropDownOpen
. To demonstrate this:
XAML:
<StackPanel>
<ComboBox x:Name="comboBoxOne"
SelectionChanged="OnComboBoxOneSelectionChanged" >
<ComboBoxItem Content="Combo Box 1 - Item 1" />
<ComboBoxItem Content="Combo Box 1 - Item 2" />
</ComboBox>
<ComboBox x:Name="comboBoxTwo">
<ComboBoxItem Content="Combo Box 2 - Item 1" />
<ComboBoxItem Content="Combo Box 2 - Item 2" />
</ComboBox>
</StackPanel>
in code behind:
private void OnComboBoxOneSelectionChanged(object sender, SelectionChangedEventArgs e)
{
comboBoxTwo.IsDropDownOpen = true;
}
Hope this helps!
Edit
If you don't want to use code-behind you have many options. For example you could create an attached behaviour or use a converter.
For example with a converter:
XAML:
<StackPanel>
<ComboBox x:Name="comboBoxOne"
SelectionChanged="OnComboBoxOneSelectionChanged" >
<ComboBoxItem Content="Combo Box 1 - Item 1" />
<ComboBoxItem Content="Combo Box 1 - Item 2" />
</ComboBox>
<ComboBox x:Name="comboBoxTwo"
IsDropDownOpen="{Binding ElementName=comboBoxOne, Path=SelectedItem, Mode=OneWay, Converter={l:NullToBoolConverter}}">
<ComboBoxItem Content="Combo Box 2 - Item 1" />
<ComboBoxItem Content="Combo Box 2 - Item 2" />
</ComboBox>
</StackPanel>
Converter:
public class NullToBoolConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Here - each time the selection changes in the first ComboBox
the Binding
on the second is updated, and the Converter
executed. I'm checking against null since we don't want it to be open on startup (in this example).
All of this assumes you already know how to set your ItemsSource
dynamically using triggers, and that the real question is how to get the second ComboBox
in an already open state :)