How can I resize the ListBox to see exactly 3 items in WPF ListBox

V

Vanja

List box should be sized in a way that only a certain number of items are
fully visible. The horizontal scrollbar should be considered, if visible.
For instance, the list box contains 10 items, but I want it to have the size
required for exaclty X items to be visible. The other items can of course be
reached by scrolling.

I didn't find any nice method or property to achieve this directly. I tried
finding out the necessary height with some formulas (e.g. height of one item
* X + border width * 2 + ??? for scroll-bar), but it's not really that
straightforward.

Since I am a beginner in WPF (and .NET), I was hoping that someone could
have an idea how to solve this problem.

Thanks,
Vanja
 
G

Gregory A. Beamer

List box should be sized in a way that only a certain number of items
are fully visible. The horizontal scrollbar should be considered, if
visible. For instance, the list box contains 10 items, but I want it
to have the size required for exaclty X items to be visible. The other
items can of course be reached by scrolling.

I didn't find any nice method or property to achieve this directly. I
tried finding out the necessary height with some formulas (e.g. height
of one item * X + border width * 2 + ??? for scroll-bar), but it's not
really that straightforward.

Since I am a beginner in WPF (and .NET), I was hoping that someone
could have an idea how to solve this problem.


You know the font you are using. You also know the point size you are
using (or pixel size). So why can't you set the height of the control to
what 3 lines of the text, plus white space, would be?

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
V

Vanja

Hello Gregory,
In spite of your signature, I must think inside the (list) box :)

Your approach is more or less what I did. However, depending on the border
thickness there is always a few pixel aberration. And additional problem: I
must somehow find out whether the horizontal scrollbar is visible, and add
its height (how many pixels, how do I find this out?) to the formula.

Thanks anyway,
Vanja
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top