开发者

WPF - Prevent Autoresize of ListBox on new Databinding?

I currently have a window with a ListBox within in. The ListBox shows the results from a search.

The开发者_如何学运维 problem I currently have is that when a search is performed and enough items are added to the ListBox, the ListBox expands vertically and forces the form to expand vertically as well.

I know I can fix this with a maxheight, but I don't want to limit the size of the form to the user, only to the program at runtime.

Is there a way I can tell the ListBox to not automatically expand or only expand when the user resizes the form?


My apologies... I've sorted out the problem. I'd mistakenly set Window.SizeToContent = "Height".

Problem solved.


Just put it in a Grid. Unless the window is set to automatically size (SizeToContent="..."), then this should work.

<Grid>

    <ListBox x:Name="lstSomeData"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch" />

</Grid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜