Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to make listbox thinner than its largest item ?

$
0
0

Hi, 

I'm facing a problem that looks simple but I can't figure out how to solve it, maybe you could help me.

I want to display a vertical list of items. I use a listbox, in a sizeable area (a grid column, but it could be a window). When I resize this listbox, I can tell it to stretch to fill the whole width of this area, but when I try to size it down it stops being resized because a textblock in it is too large. Even if it's textwrappable. 

Here is the simpliest code I could get to reproduce this (I removed the HorizontalAlignements and HorizontalContentAlignments which do not help):

<ListBox ItemsSource="{Binding}" AlternationCount="2" BorderThickness="0"  Margin="4" ><ListBox.ItemTemplate><DataTemplate><TextBlock TextWrapping="Wrap"  Text="######## ################## ######## ############# #####" /></DataTemplate></ListBox.ItemTemplate></ListBox>

It displays a list of lines with no carriage return, and a slider appears when the right side of the resizeable area approaches the last #.

How could I solve this issue ?

Thank you in advance and sorry for any mistake in my english, it's not my native language.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>