WPF ComboBox SelectionChanged事件里赋值Text的解决方法

        string sCountry ;
        private void cbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var item = cbCountry.SelectedItem as ComboBoxItem;
            if (item != null)
            {
                sCountry = item.Uid;
                //cbCountry.Text = item.Uid;//赋值将再次触发Changed事件,并且无法赋值给Text
            }
        }

        private void cbCountry_DropDownClosed(object sender, EventArgs e)
        {
            cbCountry.Text = sCountry;//只能通过DropDownClosed事件再赋值
        }

 

posted @ 2017-12-28 10:55  -Ward-  阅读(688)  评论(0编辑  收藏  举报