我的WPF应用程序中有一个复选框。当ComboBox
的选择更改应显示模态窗口时。但所选项目未反映在ComboBox
中。我用Google搜索并使用Dispatched找到了解决方案。但还有其他方法吗?
我提到MessageBox pops up behind ComboBox drop down list, obscuring content in MessageBox 为调度员。
答案 0 :(得分:0)
XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<ComboBox DropDownClosed="ComboBox_DropDownClosed">
<sys:String>A</sys:String>
<sys:String>B</sys:String>
<sys:String>C</sys:String>
</ComboBox>
</StackPanel>
</Window>
代码背后:
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ComboBox_DropDownClosed(object sender, EventArgs e)
{
MessageBox.Show((sender as Selector).SelectedItem.ToString());
}
}
}