How to style ItemsPresenter in WPF?

3.4k views Asked by At

I have a project which contains a timeline view (this one). I need the background of this timeline view to be transparent (as I am rendering other objects/controls behind it). There is an element which is coloured Opaque, so I need to change this to transparent.

If I inspect the elements in the view during debug execution, I can see that the element which needs to be changed is an ItemsPresenter (see image below). The ItemsPresenter contains a StackPanel, and when changing the colour of this stackpanel by editing its properties in the live visual tree, the issue is resolved.

Screenshot of Live Visual Tree with element highlighted

...How do I add a style for the ItemsPresenter control that can be used either globally or specifically by the timeline, changing the background of the stackpanel it contains? Are you able to provide an example?

Many thanks for your help.

1

There are 1 answers

1
mm8 On BEST ANSWER

The ItemsControl has an ItemsPanelTemplate that you can set the Background property of:

<ItemsControl ...>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Background="Gray"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    ...
</ItemsControl>