OK, I found how to do it myself.
First define our new dependence property FocusedAdapterProperty
as usual:
public static readonly DependencyProperty FocusedAdapterProperty;
static SpreadGridControl()
{
FocusedAdapterProperty = DependencyProperty.Register("FocusedAdapter",
typeof(object), typeof(SpreadGridControl),
new FrameworkPropertyMetadata(null, null));
}
public object FocusedAdapter
{
get { return GetValue(FocusedAdapterProperty); }
set { SetValue(FocusedAdapterProperty, value); }
}
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:
private void Grid_OnGotFocus(object sender, RoutedEventArgs e)
{
var control = UIHelpers.TryFindParent<ControlBase>
((DependencyObject)e.OriginalSource);
if (control != null)
FocusedAdapter = control.Adapter;
}
The implementation of TryFindParent can be found here