jode
jode

Reputation: 159

ItemsPresenter get background from expander

I have this code:

<Expander IsExpanded="True" Background="#4F4F4F">
    <Expander.Header>
        <DockPanel Height="16.5">
            <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" FontSize="11.5" VerticalAlignment="Bottom" />
            <TextBlock Text="{Binding ItemCount}" FontSize="11.5" Foreground="Orange" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
            <TextBlock FontSize="11.5" Foreground="White" FontStyle="Italic" FontWeight="Bold" VerticalAlignment="Bottom" >
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="Text" Value="sx"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ItemCount}" Value="1">
                                <Setter Property="Text" Value="s"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </DockPanel>
    </Expander.Header>
    <ItemsPresenter />
</Expander>

as you can see I have an expander and inside the expander there is an ItemsPresenter.

The expander have a black background, and it's ok, but the problem's that the ItemsPresenter get the background of the expander but this should be white of however, it shouldn't get the background of the expander, why happen this?

Upvotes: 1

Views: 441

Answers (1)

ASh
ASh

Reputation: 35720

ItemsPresenter itself doesn't have any color, it must be the cover which is visible. In ItemsControl ItemsPresenter will display ItemsPanel and different background can be set for that panel. Alternatively add a cover for <ItemsPresenter />:

<Border Background="Wheat">
    <ItemsPresenter />
</Border>

Upvotes: 1

Related Questions