Florian
Florian

Reputation: 5994

WPF expand a style

I have a listbox that is created with this code:

    <ListBox x:Name="listBox" ItemsSource="{Binding}" ItemContainerStyle="{StaticResource Office2010SilverListBoxItemStyle}"
         SelectionChanged="listBox_SelectionChanged">
</ListBox>

Now I want to apply a contextmenue to each item. How can I use my current style but with a context menue. Can i do something like a derivation from that style? Would be really great if you would know something to solve that problem... :)

Upvotes: 0

Views: 178

Answers (2)

Eduardo Brites
Eduardo Brites

Reputation: 4776

To derive from a style you can use the basedon property, for instance:

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource ButtonStyle1}">
  <Setter Property="Foreground" Value="Green"/>
</Style>

Upvotes: 0

Tim
Tim

Reputation: 15237

If you wrote the Office2010SilverListBoxItemStyle style yourself, you should be able to add something like adding another setter to it:

<Setter Property="ContextMenu">
    <Setter.Value>
        <ContextMenu>
            ...
        </ContextMenu>
    </Setter.Value>
</Setter>

Upvotes: 1

Related Questions