Hi all
I ran odd problem with listbox and its scrollbar.
I have Wpf usercontrol which contains 2 rows. First row contains textboxes and combobox and in second row contains only listbox filled with dataclass.
The dataclass is presented in listbox trough itemtemplate which contains border, textblocks and image. I have no problem with presenting my class and itemtempalates works just fine, but when I have multiple objects in my dataclasses (let say eg. 100) so my listbox doest fit my window anymore so scrollbar is needed but It doesnt show!?
I have tried to set usercontrols rowheigth to 'auto', forced to show listbox verticalscrollbar, I have even wrapped listbox inside scrollwiever but every time scrollbar remains disabled or is not showed at all.. so I think something tells to my listbox that it has enough space.. Only Solution I have found is set listbox height to known size but that is not a option.
I made simple demo of my problem
Xaml:
<grid>
<listbox grid.row="0" x:name="testlistbox" itemssource="{Binding}" scrollviewer.verticalscrollbarvisibility="Auto" xmlns:x="#unknown">
<listbox.itemtemplate>
<datatemplate>
<grid>
<border borderthickness="2" borderbrush="Blue" cornerradius="10" margin="10" padding="10">
<stackpanel>
<textblock text="SampleText"></textblock>
<textblock text="SampleText"></textblock>
<textblock text="SampleText"></textblock>
</stackpanel>
</border>
</grid>
</datatemplate>
</listbox.itemtemplate>
</listbox>
</grid>
Code:
Collection<int> SampleCollection = new Collection<int>();
for (int i = 0; i < 30; i++)
{
SampleCollection.Add(i);
}
testlistbox.ItemsSource = SampleCollection;
</int></int>
Im sure that there is easy answer to this, but I havent found it.
UPDATE: I just found out that this code works just fine in wpf window BUT in usercontrol the problem remains.. This really confuses me.
UPDATE2: Well this is kinda shame to me, but the problem lied in layout than in listbox itself. I think this case is closed. Thanks all!
I hope you got idea :)
Cheers!