private void TheTreeView_PreviewSelectionChanged(object sender, PreviewSelectionChangedEventArgs e) { if (LockSelectionCheck.IsChecked == true) { // The current selection is locked by user request (Lock CheckBox is checked). // Don't allow any changes to the selection at all. e.CancelThis = true; } else { // Selection is not locked, apply other conditions. // Require all selected items to be of the same type. If an item of another data // type is already selected, don't include this new item in the selection. if (e.Selecting && TheTreeView.SelectedItems.Count > 0) { e.CancelThis = e.Item.GetType() != TheTreeView.SelectedItems[0].GetType(); } } //if (e.Selecting) //{ // System.Diagnostics.Debug.WriteLine("Preview: Selecting " + e.Item + (e.Cancel ? " - cancelled" : "")); //} //else //{ // System.Diagnostics.Debug.WriteLine("Preview: Deselecting " + e.Item + (e.Cancel ? " - cancelled" : "")); //} }
protected override void OnSelectionChanged(SelectionChangedEventArgs e) { base.OnSelectionChanged(e); // déterminer si on doit annuler la sélection PreviewSelectionChangedEventArgs eEventArgs = new PreviewSelectionChangedEventArgs(e.AddedItems, e.RemovedItems); if (m_lLastSelectedIndex.HasValue) { if (PreviewSelectionChanged != null) { PreviewSelectionChanged(this, eEventArgs); } } // annuler (ou pas) la sélection if (eEventArgs.Cancel) { this.SelectedIndex = m_lLastSelectedIndex.Value; } else { m_lLastSelectedIndex = this.SelectedIndex; } }
protected override void OnSelectionChanged(SelectionChangedEventArgs e) { base.OnSelectionChanged(e); var eEventArgs = new PreviewSelectionChangedEventArgs(e.AddedItems, e.RemovedItems); if (m_lLastSelectedIndex.HasValue) PreviewSelectionChanged?.Invoke(this, eEventArgs); if (eEventArgs.Cancel) this.SelectedIndex = m_lLastSelectedIndex.Value; else m_lLastSelectedIndex = this.SelectedIndex; }
private void MultiSelectTreeView_PreviewSelectionChanged(object sender, PreviewSelectionChangedEventArgs e) { // multiSelectTreeView.sele var vm = (ExplorerTreeViewModel)this.DataContext; }