Different row height for items in an ObservableCollection bound to an ItemsControl, depending on the datatype

85 Views Asked by At

Does anyone know if it's possible to differ the height of each item in a ItemsControl depending on the DataType of the item in question?

Let's say I have an ObservableCollection of objects, roughly like this:

SomeItemToDraw
SomeItemToDraw
SomeItemToDraw
Divider
SomeItemToDraw
SomeItemToDraw
Divider
SomeItemToDraw

I've bound this to an ItemsControl, with different datatemplates for each type:

<ItemsControl ItemsSource="{Binding Myitems}" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <UniformGrid Columns="1" />
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
  <ItemsControl.Resources>

    <DataTemplate DataType="{x:Type example:SomeItemToDraw>
      <!-- A big ascii owl -->
    </DataTemplate>
    <DataTemplate DataType="{x:Type example:Divider>
      <!-- A single line -->
    </DataTemplate>

</ItemsControl.Resources>

Obviously in the above, each item is given equal space. So a single line is given the same space as a massive ascii owl.

Is it possible, without having a fixed collection (say it's random every time), to ensure that we still fill the parent container and ensure that the 'Divider' datatypes only get a 1px height, whilst the ascii owls get an equal share of the rest each?

Or is this not possible? In which case are we looking at a DataGrid where every bit of styling is set to be completely invisible?

0

There are 0 best solutions below