2012-08-02 17 views
0

沒有人知道爲什麼劑量SelectionChanged事件綁定ItemSoure時,列表框查看CellectionViewSource的財產被自動觸發我怎樣才能制止這種如下thanks.the代碼:??爲什麼在將ListBox的ItemSoure綁定到CellectionViewSource的View屬性時會自動觸發SelectionChanged事件?

<ListBox ItemTemplate="{StaticResource ListboxDataTemplate}" x:Name="AllListBox" SelectedItem="  Binding Master.SelectedTask,Mode=TwoWay}" ItemsSource="{Binding Master.ViewSource.View}" /> 

//Code-behind 
CollectionViewSource ViewSource = new CollectionViewSource(); 
      ViewSource.Source = Tasks; 
      ViewSource.SortDescriptions.Add(new SortDescription("Model.t_state", ListSortDirection.Ascending)); 
      ViewSource.SortDescriptions.Add(new SortDescription("Model.t_createtime", ListSortDirection.Descending)); 
      ViewSource.SortDescriptions.Add(new SortDescription("Model.t_importance", ListSortDirection.Descending)); 
      ViewSource.SortDescriptions.Add(new SortDescription("Model.t_nam", ListSortDirection.Ascending)); 

回答

0

你改變的SelectedItem或SelectedIndex在你的代碼後面的任何時間點?

+0

是的,在OnNavigatedTo方法中,這兩個屬性都被初始化,當頁面正在被導航到時。 this.AllListBox.SelectedIndex = -1; SelectedTask = null.if我不使用CollectionViewSource對此列表框中的項進行排序,一旦頁面加載後它不會被觸發 – 2012-08-03 04:03:06

+0

當您更改這些值時,選擇已更改事件被觸發。您可以使用中斷點來驗證這一點。我會建議不要在OnNavigatedTo方法中初始化它們。 – 2012-08-03 04:21:39

相關問題