I have a WPF Combobox with a ListView + "X"-Button in the Popup-DropDown. I 开发者_StackOverflowam showing search results in that listview.
How can I make the popup close ONLY when the user clicks my "X"-Button in the popup?
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;
}
}
}
精彩评论