0

I've been trying to figure this out for a few days now and I can't seem to get anywhere.

I'm working on a labeling system and to do this I have an ItemsControl that loops over an ObservabelCollection of view models and creates a child control for each item and adds that to a WrapPanel. The problem I'm running into is that the WrapPanel needs to be set to a maximum width and height, so I need to determine when the content of the wrappanel is at it's maximum width and if it is at it's max then add a +(number) to the end that indicates to the user that there are more labels applied that are not shown.

The labels can be anywhere from 1 character to 32 so I'm not sure if there's a way to use a grid with a variable number of columns with the last column being used to show the count of labels? We are trying to do this following the MVVM pattern so hopefully staying away from code behind is an option.

I would appreciate any input or help on this one, I didn't see anything like this on SO but if there is I apologize in advance.

CGideon
  • 143
  • 2
  • 15
  • Why aren't you letting it auto size and [turning on the scrollbar](http://stackoverflow.com/a/18397992/424129)? When you say "loop", do you mean you're looping through the collection and programmatically adding controls? If so, that sounds like turning a ten minute task into a few hours of work. If not, forget I said that! – 15ee8f99-57ff-4f92-890c-b56153 Apr 22 '16 at 14:21
  • I wasn't doing a scrollbar because it would not fit well in the design, the panel is a set height and the sub controls take up a good amount of space in the panel in order to be readable by the user. And by "loop" I mean I'm setting an ObservableCollection property on the VM and setting that as the itemsource of the ItemsControl and then setting the ItemsControl.ItemTemplate to be the custom control. – CGideon Apr 22 '16 at 15:27
  • Oh good, that's what I was hoping to hear about the loop. You might be able to replace the scrollviewer's template so it displays the plus sign control instead of a scrollbar. Honestly I've messed a bit in WPF with programatically handling size-changing stuff, and it was painful and frustrating. This isn't MFC. The best choice is just about always to use existing behavior and retemplate it. – 15ee8f99-57ff-4f92-890c-b56153 Apr 22 '16 at 15:33
  • You should probably replace the WrapPanel by a [Custom Panel](https://msdn.microsoft.com/en-us/library/ms754152(v=vs.100).aspx#Panels_custom_panel_elements) that only arranges those child elements that fit into its bounds, and optionally displays the + label when there are more children. – Clemens Apr 26 '16 at 06:21

0 Answers0