0

I have a Menu which has an ItemContainerStyle

<Menu DockPanel.Dock="Top" ItemContainerStyle="{StaticResource MenuItemStyle}" ItemsSource="{Binding MenuItems}">

This particoular ItemContainerStyle has a trigger defined like in How can I bind key gestures in Caliburn.Micro?

<Style TargetType="{x:Type MenuItem}"  x:Key="MenuItemStyle" BasedOn="{StaticResource {x:Type MenuItem}}">
[...]
<Setter Property="int:InteractivityItems.Template">
    <Setter.Value>
        <int:InteractivityTemplate>
            <int:InteractivityItems>
                <int:InteractivityItems.Triggers>
                    <triggers:InputBindingTrigger InputBinding="{Binding Shortcut, Converter={StaticResource StringToKeyBinding}}">
                        <cal:ActionMessage MethodName="Execute"/>
                    </triggers:InputBindingTrigger>
                </int:InteractivityItems.Triggers>
            </int:InteractivityItems>
        </int:InteractivityTemplate>
    </Setter.Value>
</Setter>
[...]

The problem I am facing is that this trigger is attached to menu item children only when, for example, I open the menu instead of its creation and therefore thr InputBindingTrigger does not work except when opening and then closing the menu.

Is there any way to force the application of ItemContainerStyle when the menu is created instead of openened?

Community
  • 1
  • 1
Mattias Cibien
  • 296
  • 2
  • 16
  • In wpf, most of the visual tree elements are created when they come into view. When a Menu opens the first time, the items are created just then, when the Open command is dispatched, and not before. What do you want to do ? – deafjeff Nov 20 '14 at 14:34
  • The high level goal is is to add keybindings to the mus items. So for File->New for example, I need to have Ctrl+N already avaialble without having to open the menu first. Anyway I was able to fix this in another way by using the Window InputBindings. – Mattias Cibien Nov 24 '14 at 10:05
  • Good! Could you answer your own question ? That would be great to let others know they don't need to post an answer. You also can get upvotes for your answer. – deafjeff Nov 28 '14 at 07:33
  • Actually the solution i found is not related to the question since it uses another approach. I do not want to go off topic. – Mattias Cibien Nov 28 '14 at 10:58

0 Answers0