WPF DockPanel doesn't respect the "Filled" control's desired size

Posted by Dan Puzey on Stack Overflow See other posts from Stack Overflow or by Dan Puzey
Published on 2010-03-08T17:58:35Z Indexed on 2010/03/08 18:06 UTC
Read the original article Hit count: 347

Filed under:
|
|

I have the following Xaml (simplified for brevity, but will repro the problem in Xamlpad or Kaxaml):

<DockPanel Width="400">
    <TextBlock DockPanel.Dock="Left" TextWrapping="Wrap">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        Vestibulum massa metus, ornare in fringilla nec, fringilla at orci.
        Nunc pharetra enim sit amet sapien aliquet eu euismod turpis vehicula.
        Aenean gravida tempus lectus ut ornare. 
            Nullam massa augue, suscipit vel consectetur fringilla, pretium vitae neque.
    </TextBlock>
    <Button MinWidth="100" VerticalAlignment="Center" HorizontalAlignment="Left">Hello world</Button>
</DockPanel>

My problem is that I want the Button to take its minimum 100px of space, and for the text to wrap suitably to leave that space. However, what happens is that the text wraps as close to 400px as possible, and then the Button is clipped.

If I Snoop the output I can see that the button is rendering at the desired 100px, but it's being clipped off the side of the DockPanel.

If I reverse the Dock (so the button is docked "Right" and the TextBlock fills) then I get the layout I want, but unfortunately that's not an option due to the surrounding layout.

Is there something I can do that will make the DockPanel a) not clip and b) layout in a way that respects the MinWidth? Or am I stuck finding an alternative layout mechanism?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about xaml

Related posts about dockpanel