el-nino
el-nino

Reputation: 399

WPF ListBox vertical scrollbar covers part of the items. How to resize the content to match the size of the ListBox?

i have a ListBox which is filled with images as items. works all fine and as intended so far. but the vertical scrollbar covers the right part of the images. how can i prevent that?

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Hidden">
    <ListBoxItem>
        <Image Source="/BFH;component/Images/PackingPictures/1.jpg"/>
    </ListBoxItem>
    <ListBoxItem>
        <Image Source="/BFH;component/Images/PackingPictures/2.jpg"/>
    </ListBoxItem>
</ListBox>

without a scrollbar with a scrollbar

Upvotes: 0

Views: 1197

Answers (1)

el-nino
el-nino

Reputation: 399

thanks to dkozl, here is the right answer:

HorizontalScrollBarVisibility="Hidden" does not disable horizontal scrolling only hides horizontal scrollbar. Try with Disable otherwise your item is given more space horizontally then you can see.

so the solution is:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disable">
    <ListBoxItem>
        <Image Source="/BFH;component/Images/PackingPictures/1.jpg"/>
    </ListBoxItem>
    <ListBoxItem>
        <Image Source="/BFH;component/Images/PackingPictures/2.jpg"/>
    </ListBoxItem>
</ListBox>

Upvotes: 2

Related Questions