我有一個方法如何確定TextChanged是否由C#中的鍵盤觸發?
private void textBoxPilot_TextChanged(object sender, TextChangedEventArgs e)
{ ... }
如有關的文本需要來自用戶的搜索字符串,並填充與每個按鍵的結果ListBox
。
隨後,當從ListBox
中挑選物品時,我希望選擇反映在相同的Textbox
中。但是,我不想觸發搜索機制,這會導致Listbox
忘記選擇。
如何確定TextChanged
事件是由用戶(通過它們的鍵盤還是複製/粘貼)還是由其他方法使用textBoxPilot.Text = "Pilot name";
觸發的?
謝謝。
最後我用你的答案和斯科特的回答的組合: 私人無效listBoxPilot_SelectionChanged(對象發件人,SelectionChangedEventArgs E) { textBoxPilot.IsEnabled = FALSE; Member selectedPilot =(Member)listBoxPilot.SelectedItem; textBoxPilot.Text = selectedPilot.firstName; textBoxPilot.IsEnabled = true; } 私人無效textBoxPilot_TextChanged(對象發件人,TextChangedEventArgs E) { 如果(textBoxPilot.IsEnabled == FALSE) 回報; [search stuff] } 這消除了對新的全局變量的需求。感謝你們倆。 – Anders 2010-09-02 21:56:00