Autor Beitrag
DrHoas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Sa 13.02.16 22:54 
Hallo,

ich möchte die Höhe einer ListBox so anpassen, dass sie immer genau so groß ist, dass alle Items reinpassen. In WinForms hab ich das so gemacht:
ausblenden C#-Quelltext
1:
lb.Height = (lb.Items.Count + 1) * lb.ItemHeight;					

In WPF gibt es die Eigenschaft ItemHeight aber nicht. Oder hab ich da was übersehen?

Dank und Gruß

Philipp

Moderiert von user profile iconChristian S.: Code- durch C#-Tags ersetzt
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 14.02.16 11:04 
Hallo,

setze einfach die Height der ListBox/ListView auf auto (im XAML-Code).
Falls du doch eine Obergrenze brauchst, dann kannst du noch zusätzlich MaxHeight vorgeben.
DrHoas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: So 14.02.16 13:00 
Oha, das war einfach.
Ich hatte das zwar probiert, es hatte aber nicht funktioniert, weil ich noch margins eingegeben hatte.

Danke nochmal.

Philipp