0
votes

I have WPF window with ListBox that contains items of TextBlock. Each TextBlock have different font size and text length. When I fill my collection it's include scrollbar for viewing the result.

What is the best way to fit the items size(something like zoom) to fit the ListBox that it will show all the items in the current window without scrolling?
(When ScrollViewer.HorizontalScrollBarVisibility="Disabled" and also ScrollViewer.VerticalScrollBarVisibility="Disabled")

Is there any WPF way or some kind of algorithm to do so?

1
Can you provide a little bit of code you already have?voytek

1 Answers

1
votes

I had an issue similar to yours before, and could only solve it using a ViewBox.

<ViewBox Stretch="Uniform">
    <ListBox>...</ListBox>
</ViewBox>

If needed, you could also bind some dimension of a given control a dimension of another, for example:

<ViewBox x:Name="vb" Stretch="Uniform">
    <ListBox Width={Binding ActualWidth, ElementName=vb>...</ListBox>
</ViewBox>    

But due to different layout characteristics of each container type (if it expands or shrinks, or if it tells its children to expand or not), you'd have to try different approaches until the layout works as you intend.