WPF/Metro-style: Making ListView show only complete items

前端 未结 3 501
长情又很酷
长情又很酷 2020-12-21 08:29

In my Metro application, I have a data source containing a certain number of items (say 25). I have a ListView that presents those items. My problem is that the ListView hav

3条回答
  •  情话喂你
    2020-12-21 09:26

    ListView inherits from ItemsControl, so one more optimized solution consists in injecting custom panel (overriding measure by custom clipping display) in ItemsPanel

    something like this(sorry, i did not try to compile):

    protected override Size MeasureOverride(Size constraint)
    {
     if (this.VisualChildrenCount <= 0)
      return base.MeasureOverride(constraint);
     var size = ne Size(constraint.Width,0);
     for(int i = 0; i < this.visualChildrenCount; i++)
     {
      child.Measure(size);
      if(size.height + child.desiredSize > constraint.height)
       break;
      size.Height += child.DesiredSize;
     }
     return size;
    }
    

提交回复
热议问题