How to make WrapPanel with some elements having height *?
Deceptively simple question that I tried to solve. I want a control (or some XAML layout layout) that behaves similarly to a grid that has multiple rows with a height * but supports column wrapping. Hell; name it WrapGrid. :)
Here is a layout to visualize this. Imagine a grid defined as such:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="400"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Button Grid.Row="0" MinHeight="30">I'm auto-sized.</Button> <Button Grid.Row="1" MinHeight="90">I'm star-sized.</Button> <Button Grid.Row="2" MinHeight="30">I'm auto-sized.</Button> <Button Grid.Row="3" MinHeight="90">I'm star-sized, too!</Button> <Button Grid.Row="4" MinHeight="30">I'm auto-sized.</Button> <Button Grid.Row="5" MinHeight="30">I'm auto-sized.</Button> </Grid> </Window>

What I want this panel to do is move the element to an extra column when the element cannot be smaller than its minHeight. Here is the awful MSPaint of some of the layouts that I described in detail in this process,

Recall from XAML that auto-sized buttons have minHeights 30, and star-sized buttons have minHeights 90.
This layout is just two gratings side by side, and I manually moved the buttons around in the designer. Apparently, this could be done programmatically and served as a kind of minimized solution for this.
How can I do that? I agree with any solution, whether through xaml or has some code (although I would prefer pure XAML if possible, since the xaml code behind is more difficult to implement in IronPython).
Updated with reward
Meleak Solution
I was able to decide how to use the Meleak solution in my IPy application:
1) I compiled WrapGridPanel.cs in a DLL with csc :
C:\Projects\WrapGridTest\WrapGridTest>csc /target:library "WrapGridPanel.cs" /optimize /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationCore.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\WindowsBase.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xaml.dll"
Update: Added /optimize switch, this provides a slight increase in performance
2) I added it to my xaml application with the following line.
xmlns:local="clr-namespace:WrapGridTest;assembly=WrapGridPanel.dll"
This works fine, but it breaks the constructor. At the moment I can not find a workaround, it seems this is a bug in VS2010. Since the workaround is to be able to use the constructor, I just add the WrapGridPanel programmatically at runtime:
clr.AddReference("WrapGridPanel.dll") from WrapGridTest import WrapGridPanel wgp = WrapGridPanel()
Slow performance when resizing :
In my IronPython application, resizing the window containing this WrapGridPanel is slow and inhibited. Is it possible to optimize the RecalcMatrix() algorithm? Maybe this can be called less often? Maybe redefining MeasureOverride and ArrangeOverride , as Nicholas suggested, would work better?
Update . According to the VS2010 Instrumentation Profiler, 97% of the time spent on RecalcMatrix () is spent on Clear () and Add (). Modifying each item in place will be a huge performance improvement. I take the brunt, but it always changes the code of another one hard. http://i.stack.imgur.com/tMTWU.png
Update: Performance issues are mostly fixed. Thanks Meleak!
Here is the layout of part of my actual application user interface in XAML if you want to try it. http://pastebin.com/2EWY8NS0