Is there a panel I can use in WPF that will "defeat" SizeToContent?

I basically want certain parts of my window to not affect SizeToContent (things like a title bar) so that it appears to have no size and collapses. Is there a panel I can use to do this (like a ScrollViewer maybe?) or do I have to write my own?

Answers


You need a control that will return (0,0) from MeasureOverride. Canvas will do this, but it may not have other behavior you want. You could also subclass an existing panel, like Grid, and just return an empty size:

public class ZeroGrid
    : Grid
{
    protected override Size MeasureOverride(Size constraint)
    {
        base.MeasureOverride(constraint);
        return new Size();
    }
}

That will behave like a Grid, so its content will stretch to its actual size, but it will always have a DesiredSize of zero so it won't affect SizeToContent.


Need Your Help

c# Label Visible and Invoke

c# windows-mobile invoke

I'm devolping a Windows Mobile aplication in Compact Framework 2.0 SP1.

How to setup iOS MDM server?

ios server enterprise mdm

My app has been released previously.