AvalonDock Now Loses Alt Key Adornments

耗尽温柔 提交于 2019-12-01 18:36:27

It sounds as though this will be fixed with the next version of AvalonDock.

In the meantime, the following Blend behavior is a workaround:

public class FixKeyboardCuesBehavior : Behavior<UIElement>
{
    private static readonly DependencyProperty ShowKeyboardCuesProperty;

    static FixKeyboardCuesBehavior()
    {
        Type keyboardNavigation = typeof(KeyboardNavigation);
        var field = keyboardNavigation.GetField("ShowKeyboardCuesProperty", BindingFlags.NonPublic | BindingFlags.Static);

        Debug.Assert(field != null, "field != null");

        ShowKeyboardCuesProperty = (DependencyProperty)field.GetValue(null);
    }

    protected override void OnAttached()
    {
        base.OnAttached();

        Window rootWindow = Window.GetWindow(this.AssociatedObject);
        if (rootWindow == null)
        {
            return;
        }

        BindingOperations.SetBinding(
            this.AssociatedObject,
            ShowKeyboardCuesProperty,
            new Binding("(KeyboardNavigation.ShowKeyboardCues)") { Source = rootWindow });
    }
}

Use this from XAML by adding the following to the root element of your DataTemplate for the AvalonDock LayoutItemTemplate:

<i:Interaction.Behaviors
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
    <my:FixKeyboardCuesBehavior />
</i:Interaction.Behaviors>

This workaround uses internal implementation details of WPF to re-introduce the Alt behaviour below the broken AvalonDock logical tree. So, I'll be looking forward to being able to zap it from my code when AD itself is fixed!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!