views:

50

answers:

1

I have a WPF Combobox with a ListView + "X"-Button in the Popup-DropDown. I am showing search results in that listview.

How can I make the popup close ONLY when the user clicks my "X"-Button in the popup?

A: 

You will probably have to write a custom control template for a permanently open listbox, or change the default one to behave like this. Inside the control template you have to set the StaysOpen property of the Popup to true and make your button switch that value

Short example

<Window x:Class="WPFComboSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ComboBox Name="Combo">
        <TextBox></TextBox>
        <Button Name="Close" Width="150" Height="200" Click="Close_Click">Close</Button>
    </ComboBox>
</Grid>

namespace WPFComboSample
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml>
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Close_Click(object sender, RoutedEventArgs e)
    {
        Combo.IsDropDownOpen = false;
    }


}

}

Semyazas
I changed the control template of the combobox popup. Now the close button show at the bottom of the Combobox`s popup. But how can I make in binding to close the popup when I press the button ?
Lisa
This has been answered here:http://stackoverflow.com/questions/1425255/wpf-how-combobox-knows-when-to-close-the-drop-down-menu
Semyazas
1. There is no solution 2. My requirement is different. => I have a button below the Scrollviewer inside the popup template. I need to connect the button with the IsDropDownOpen property somehow...
Lisa
I actually misread that other post/answer. What you want to do is refer to the IsDropDownOpen of the Combobox, not of the Popup as its child. Please see my edit for reference
Semyazas
A terrible approach and not reusable at all Semyazas :/ Anyway I used a ToggleButton instead with IsChecked=True that works but now I have other quirks... seems someone have to do that from scratch, so I drop that question.
Lisa