Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a ComboBox with which I would like to automatically open the drop-down element in certain situations.

The ComboBox is defined as follows:

HTML
<ComboBox x:Name="WorkTypeTemplates" Margin="5,0,5,0"
                    Foreground="{StaticResource SETISelection}" ItemsSource="{Binding}" 
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                    SelectionChanged="TemplateChanged" >
            <ComboBox.ItemTemplate>
              <DataTemplate>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="{Binding HeaderLabel}" />
                </StackPanel>
              </DataTemplate>
            </ComboBox.ItemTemplate>
          </ComboBox>


... with the IsDropDown property being set in code according to the contents of the list.

When IsDropDown set to "True", as the form opens the pop-up will open and then close again (checking with Snoop, IsDropDown has been reset to "False").

I've tried setting/resetting the property at various points using the Loaded events on both the form and the control but everything that I've tried has lead to the same result.

I'm sure that I'm missing something blindingly obvious (XAML and front-ends in general really aren't my specialist subject) but this is driving me potty as it's something that should be a very trivial change. Any help would be greatly appreciated.
Posted

1 solution

I cannot get it to fail...

I created a simple WPF application that has a ComboBox and a Button. The constructor of the Window sets the IsDropDownOpen property to true. And then the Button will do the same.

You left out the details of what criteria you use to determine if that is true or not, but you should be able to specify it there, or you can use triggers within the XAML.

The following code shows my demo application:

XAML (some elided for brevity)
<ComboBox x:Name="MyComboBox" Margin="5 0 5 0" Grid.Column="0"
            ItemsSource="{Binding Path=.}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=.}" />
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
<Button Grid.Column="2" Margin="0 0 5 0"
        Content="Open DropDown"
        Click="Button_Click" />


Code-behind (some elided for brevity)
C#
readonly List<string> items = new List<string>() { "One", "Two", "Three" };

public MainWindow()
{
    InitializeComponent();
    DataContext = items;

    MyComboBox.IsDropDownOpen = true;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    MyComboBox.IsDropDownOpen = true;
}</string></string>
 
Share this answer
 
v3
Comments
PeejayAdams 2-Jun-14 6:21am    
Thanks tgrt - sorry for the delay in replying, I've been on holiday.

I've tried creating a stand-alone test form and everything works as expected as it does for you. So there's something in my app that's manipulating the IsDropDown property indirectly (maybe via the IsOpen property on the internal Popup) but I'm just not seeing it. I'll let you know when I find something.

Thanks again for having a look - it's much appreciated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900