【问题标题】:ComboBox is not populated if the message box is popped up in the selectionchanged event in WPF如果在 WPF 中的 selectionchanged 事件中弹出消息框,则不会填充 ComboBox
【发布时间】:2012-05-29 22:37:28
【问题描述】:

我的 WPF 应用程序中有一个复选框。当ComboBox 的选择更改时应显示一个模式窗口。但所选项目未反映在ComboBox 中。我用谷歌搜索并找到了使用 Dispatched 的解决方案。但是有没有其他方法可以做到这一点?

我推荐了MessageBox pops up behind ComboBox drop down list, obscuring content in MessageBox 为调度员。

【问题讨论】:

  • @Tanya:您使用 Dispatcher 找到了什么解决方案?还有其他方法可以做什么吗?您没有清楚地描述您遇到的问题,所以这不是一个容易回答的问题。
  • @Tanya,你拼错了,我会帮你改的

标签: c# .net wpf


【解决方案1】:

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());
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    • 2021-03-17
    • 2012-01-29
    • 2014-05-02
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    相关资源
    最近更新 更多