tags:

views:

18

answers:

1

This is probably a newbie question :)

I have some styles and content templates for a contextmenu defined in a window (alternatively I could move them to app.xml)

The contextmenu is created programmatically so I need to assigned the style and content template to it programmatically (which is set to targettype contextmenu and menuitem). How do I do that?

If i give them specific keys I could use findresource and assign the template property etc, but there's lot's of bindings in the templates that get screwed up when I do that :/

A: 

You can create styles in code, here is how to do it. But in my personal view, everything which is related to your UI should stay in XAML, is possible. In your case findresource is the way to go. And all the bindings should work correctly.

Could you post your XAML?

Vitalij
Agreed, don't want to do it by code. But how do I use findresource to find a controltemplate defined with a key like this: <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="MenuItem"> and styles like this <Style x:Key="{x:Type MenuItem}" TargetType="MenuItem">
MattiasK