日期:2014-05-17  浏览次数:20747 次

WPF 奇怪的问题,求解答
最近用wpf做一个东西,发现点击一个按钮增加数据到数据库里面时,要点击2次才会添加成功,但是当我把容器stackpanel去掉后 ,一次就可以成功,就增加按钮需要点击2次,其他删除 更新==都不需要,我以为是stackpanel问题,但是我在按钮事件中只写一个MessageBox时完全没问题,是不是有点莫名其妙啊,
Instrument mySelectedElement = (Instrument)dataGridinstrument.SelectedItem;
                if (dataGridinstrument.SelectedItem == null)
                {
                    return;
                }

                string result = mySelectedElement.name.ToString();
                string result1 = mySelectedElement.mode.ToString();
                string result2 = mySelectedElement.port.ToString();
                string result3 = mySelectedElement.IP;

                string str_insert = “。。。";
                ExecuteQuery(str_insert);
                LoadDataGridInstrument();

------解决方案--------------------
private void calendar1_PreviewMouseUp(object sender, MouseButtonEventArgs e)
    {
        if (Mouse.Captured is CalendarItem)
        {
            Mouse.Capture(null);
        }
    }希望帮到你
------解决方案--------------------
删除事件,重新绑定一下