Skip to content

ListBox.ItemTemplate doesn't stretch entire background #666

@J0nathan550

Description

@J0nathan550

I noticed when I was preparing my ListBox item template. I wanted to make entire ListBoxItem background to be ImageSourceBrush. But unfortunately by default the ListBox Item doesn't stretch the whole width and height.

Overriding the ItemContainerStyle will break the modern style of ListBox.

Any ideas how to stretch the grid to an entire ListBoxItem?

Code:

        <ListBox ItemsSource="{Binding SongsList}" SelectedItem="{Binding CurrentSong}" Background="Black" Margin="0,5,0,0">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="models:SongModel">
                    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Tag="{Binding SongLink}">
                        <Grid.Background>
                            <ImageBrush Stretch="UniformToFill" ImageSource="{Binding Icon}" Opacity="0.5" RenderOptions.BitmapScalingMode="Fant"/>
                        </Grid.Background>
                        <TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis"/>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions