0

I've an ItemsControl with the following code:

<ItemsControl ItemsSource="{Binding SomeModelList}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <controls:SomeUserControl ModelValue="{Binding}"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

But visually, I've only one column of items, and some items are not displayed(overflow on the bottom of the windows). What should I do to get those in two column when not space available?

Edit

in fact, if I set a "MaxWidth", I get two column, but this is still not working as expected, because if I've not a lot of items, they should be on one column and use the available space

Edit 2

Some more informations: My container(the one with the ItemsControl) is a window, that contains a Grid. One of the cell is allocated to this ItemsControl. It is set to use all the remaining space.

The userControl are composed with one DockPanel, which contains some textBlock and a graphic. Even if there is no Height specified, this control cannot grow in height, but in width.

J4N
  • 19,480
  • 39
  • 187
  • 340
  • Have you tried setting a MaxHeight / VerticalAlignment, so the WrapPanel knows when it should wrap? – Manfred Radlwimmer Jul 04 '16 at 06:03
  • @ManfredRadlwimmer Actually not, because the day I add 1 control within my UserControl, I don't want to have to look all the usages to find where its value has been fixed(I just tested it, it doesn't seems to help if I add a `MaxHeight` on the SomeUserControl usage – J4N Jul 04 '16 at 06:13
  • 1
    No I meant on the WrapPanel in the ItemsPanelTemplate, just to test if it's just a layouting problem. If it wraps when a MaxHeight is set and the VerticalScrollBar is disabled, it would be a completely different problem as when it doesn't. – Manfred Radlwimmer Jul 04 '16 at 07:12
  • I have tried your code and for me works. I just have set the height of the item control. Obviously it depends from your layout. – Babbillumpa Jul 04 '16 at 07:15
  • Just put the ItemsControl in a Panel that sets its size, e.g. a Grid. A Canvas won't do. – Clemens Jul 04 '16 at 07:35
  • How is the user control defined? Does it define any height. I think the problem is the wrap panel gets undefined height when layouting its items so it cannot split it into columns. – michauzo Jul 04 '16 at 07:48
  • @cicciorocca I cannot set a fixed size, since the goal is to adapt to the size of the window. – J4N Jul 04 '16 at 07:54
  • @Clemens It's within a Grid, but the cell has `*` sizes(since it should take sthe available size – J4N Jul 04 '16 at 07:55
  • @michauzo The usercontrol is one DockPanel, and within it, 2 others controls. There is no explicit size set. – J4N Jul 04 '16 at 07:57
  • I supposed it...However it should work. – Babbillumpa Jul 04 '16 at 08:16
  • @cicciorocca in fact the issue is that every item is capable of using the full width available, so the WrapPanel doesn't wrap since it thinks there is not enough space – J4N Jul 04 '16 at 08:41
  • 1
    AFAIK WrapPanel with vertical orientation will eventually overflow horizontally. It can only overflow vertically if height of single item is bigger then the height of the Panel. I don't think the issue is items' width, I rather think it's related to items' height. Is it possible to extract a code example that will allow us to reproduce the problem? – michauzo Jul 04 '16 at 08:49
  • @michauzo While trying to create a sample, i did notice something: Within my UserControl, I've a DevExpress chart(which has a fixed height, but can use as much width as he is provided). If I replace it with something else, I don't have the issue anymore – J4N Jul 04 '16 at 09:22

0 Answers0