I have MyContainer User Control with Grid inside. Each cell of this Grid contains a some control derived from MyControlBase class. These controls are added dynamically.
I need to implement a FocusedControl bound property in MyContainer to get currently focused or set focus to any of MyControlBase children. I know about FocusManager.FocusedElement but haven’t ideas how to implement it properly.
OK, I found how to do it myself.
First define our new dependence property
FocusedAdapterPropertyas usual:Next add GotFocus handler to parent container e.g.
<Grid GotFocus="Grid_OnGotFocus">Check the e.OriginalSource and search most common ancestor of required type and set property to new value:
The implementation of TryFindParent can be found here