AvalonDock Now Loses Alt Key Adornments
Asked Answered
U

1

4

I've been using AvalonDock (2.0) for some time now, being key for managing documents in an IDE. In the last month or so, I've noticed that Alt key adornments are no longer showing up for controls within AvalonDock, though the Alt key commands are executing as expected. See the image below where the Alt key adornments are showing up in the menu, but not for the buttons inside AvalonDock:

No Alt Keys

What is particularly interesting about this issue, that it appears to be triggered by an environmental setting or condition.

As demonstrated in this video (at 2:07), the alt key adornments are working for a control within AvalonDock. But, if I now use the very same executable I used in that video, the alt key adornments do not work.

I'm currently using build 2.0.1746, but I also tried build 2.0.2000 (with the Xceed namespace) and found the same issue. I also tried the version packaged with the Xceed Extended WPF Toolkit, and found that the issue persists.

I also built a very simple test application which loads a couple of documents of type Item, where Item is a simple class with a Name property:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        xmlns:avalonDock="clr-namespace:Xceed.Wpf.AvalonDock;assembly=Xceed.Wpf.AvalonDock"
        xmlns:avalonDockLayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
        xmlns:avalonDockControls="clr-namespace:Xceed.Wpf.AvalonDock.Controls;assembly=Xceed.Wpf.AvalonDock"
        Title="MainWindow" Height="500" Width="500">
    <Window.Resources>
        <ResourceDictionary>
            <DataTemplate DataType="{x:Type local:Item}">
                <StackPanel Orientation="Vertical">
                    <Label Content="Item:" />
                    <TextBox Text="{Binding Name}"/>
                    <Button Content="_ClickMe" />
                </StackPanel>
            </DataTemplate>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"></RowDefinition>
          <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <avalonDock:DockingManager Grid.Row="0"  DocumentsSource="{Binding}">
            <avalonDockLayout:LayoutRoot>
                <avalonDockLayout:LayoutPanel Orientation="Horizontal">
                    <avalonDockLayout:LayoutDocumentPane/>
                </avalonDockLayout:LayoutPanel>
            </avalonDockLayout:LayoutRoot>
        </avalonDock:DockingManager>
        <Button Grid.Row="1" Content="_Test" />
    </Grid>
</Window>

Even with this simple application, the Alt key adornments show up for the Test button outside of AvalonDock, but not for the ClickMe buttons for the controls within AvalonDock.

I also posted the issue here on the AvalonDock codeplex site, but there appears to be very little response activity. I also posted the issue here on the Extended Toolkit codeplex site.

Any ideas on how to correct or workaround this issue?

Unbeknown answered 17/11, 2013 at 22:15 Comment(2)
If you have an Xceed subscription, it might be worth contacting their support people. You might also want to try their own forum: xceed.com/CS/forums/86/ShowForum.aspxLinneman
Thanks Richard, I will post on that forum as well, and maybe get a subscription.Unbeknown
S
2

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!

Shelve answered 13/4, 2014 at 22:34 Comment(1)
Thanks Olly, I'm going with your workaround in the meantime as well. Should be fixed in Xceed Wpf Toolkit 2.3.Unbeknown

© 2022 - 2024 — McMap. All rights reserved.