In ItemsControl items are in a ContentPresenter, so if a item has Visibility='collapsed' its ContentPresenter still have Visibility='Visible'... (Here is explained this behaviour)
So these 2 examples doesn't show the same result:
This works as I expect:
<UniformGrid Columns="1">
<Button Content="0"/>
<Button Content="1"/>
<Button Content="2" Visibility="Collapsed"/>
<Button Content="3"/>
</UniformGrid>
This doesn't work as I expect (UniformGrid reserve the space for the third button also if it is collapsed):
<ItemsControl>
<ItemsControl.ItemsSource>
<x:Array Type="{x:Type System:Int32}">
<System:Int32>0</System:Int32>
<System:Int32>1</System:Int32>
<System:Int32>2</System:Int32>
<System:Int32>3</System:Int32>
</x:Array>
</ItemsControl.ItemsSource>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Visibility="{Binding ., Converter={StaticResource CalculatorConverter}, ConverterParameter=IIF(\{0\}\=2\,\'Collapsed\'\,\'Visible\')}" Content="{Binding .}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Anyone got this problem? Is there a workaround?