TreeListBox changes selected item when focused

Grids for WPF Forum

Posted 1 year ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 22.1.4
Avatar

Hi,

we have a two-way binding to the SelectedItem property of the TreeListBox. And somehow the SelectedItem is changed when the parent view is focussed. The control is used in a tabbed MDI document. I am not even sure why the TreeListBox receives the focus, when actually another control inside the view should be focused. Anyhow, the SelectedItem should not be affected regardless of the focus.

Do you have an idea, how this behavior can be stopped? Here is a callstack, when the SelectedItem is changed:

PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.SetValue()
PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateSource()
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.UpdateValue()
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ProcessDirty()
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Dirty()
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.SetValue()
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon()
ActiproSoftware.Grids.Wpf.dll!ActiproSoftware.Windows.Controls.Grids.TreeListBox.SelectedItem.set()
ActiproSoftware.Grids.Wpf.dll!ActiproSoftware.Windows.Controls.Grids.TreeListBox.m5D()
ActiproSoftware.Grids.Wpf.dll!ActiproSoftware.Windows.Controls.Grids.TreeListBox.z5H()
ActiproSoftware.Grids.Wpf.dll!ActiproSoftware.Windows.Controls.Grids.TreeListBoxItem.OnGotFocus()
PresentationCore.dll!System.Windows.UIElement.IsFocused_Changed()
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged()
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged()
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange()
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue()
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon()
WindowsBase.dll!System.Windows.DependencyObject.SetValue()
PresentationCore.dll!System.Windows.Input.FocusManager.OnFocusedElementChanged()
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged()
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged()
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange()
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue()
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon()
PresentationCore.dll!System.Windows.Input.FocusManager.SetFocusedElement()
PresentationFramework.dll!System.Windows.Input.KeyboardNavigation.UpdateFocusedElement()
PresentationFramework.dll!System.Windows.FrameworkElement.OnGotKeyboardFocus()
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler()
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler()
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl()
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl()
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput()
PresentationCore.dll!System.Windows.Input.KeyboardDevice.ChangeFocus()
PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus()
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus()
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus()
PresentationCore.dll!System.Windows.UIElement.Focus()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Internal.GA.SY4()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Internal.GA.UYy()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Internal.GA.pY2()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Internal.GA.fhz()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Internal.GA.TYI()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Internal.GA.fhz()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Windows.Controls.Docking.AdvancedTabControl.jw()
ActiproSoftware.Docking.Wpf.dll!ActiproSoftware.Windows.Controls.Docking.AdvancedTabItem.R23()
ActiproSoftware.Shared.Wpf.dll!ActiproSoftware.Windows.Input.InputAdapter.L1i()
ActiproSoftware.Shared.Wpf.dll!ActiproSoftware.Windows.Input.InputAdapter.b1Y()
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler()
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler()
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl()
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl()
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput()
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput()
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput()
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage()
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage()
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc()
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation()
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall()
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen()
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl()
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc()
[Native to Managed Transition]	
[Managed to Native Transition]	
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl()
PresentationFramework.dll!System.Windows.Application.RunDispatcher()
PresentationFramework.dll!System.Windows.Application.RunInternal()


Best regards, Tobias Lingemann.

Comments (2)

Answer - Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tobias,

For the upcoming 23.1 version, we've already added a new feature that would help you in this scenario:

Added the TreeListBox.CanSelectItemOnFocus property and updated TreeListBox/TreeListView to not select an item when it first gets focus by default, which matches ListBox behavior.

That being said, it's probably better to have it avoid getting focus by the docking window to begin with if you say that isn't the intention.  A docking window will try and focus the last-focused element within it if it previously contained focus.  If instead this is a new docking window, it will go through several steps to try and find a focusable descendant in the visual tree.  As long as you declare your intended focus target first in the visual tree and it's Focusable and has a tab stop, it should find that and use it first.


Actipro Software Support

Posted 1 year ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

I will check out the proeprty, once we have updated to the latest version. I think this will solve the problem.

The focus is changed to the correct control afterwards, but by then we already reacted to the changed node.


Best regards, Tobias Lingemann.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.