The online racing simulator
[OT] WPF Docking Help
(10 posts, started )
[OT] WPF Docking Help
Hello,

I'm currently working with WPF and C# for the first time, and I've found a really annoying problem that I've spent the last few hours trying to solve.

I have a WPF user control which I host inside a Windows form. That all works very well (I was actually becoming a WPF fan...), but I want the child control to fill the entire host control. In Windows.Forms I can normally just call Dock = DockStyle.Fill, but there doesn't seem to be any WPF equivalent.

I'm faced with the extremely boring notion of having to programmatically resize an extremely complex control every time the window is resized.

Surely Microsoft must have made a solution to this issue?

Thanks.
This should answer your question Scroll down to 'Anchoring and Docking WPF Controls'
Thanks for the reply, but that is explaining how to dock the WPF host inside a Windows form. My problem is how to get the WPF elements inside the host to dock. I can't find any way for them to expand and fill it.
Doh, sorry, misunderstood! I have no idea, then, sorry... WPF is not an area I've really ventured into.
No idea if this is at all relevant, or at all what you're looking for, but a little way down here it talks about Viewbox.Stretch (MSDN)...
Quote from JamesF1 :Doh, sorry, misunderstood! I have no idea, then, sorry... WPF is not an area I've really ventured into.

Me neither, and neither has anyone else it seems. That's the problem.

Anyway, I have a solution. I hooked up a Resize event to the main Windows form, and when the form is resized it passes the new size of the docked host control to the child element that's inside it, which then resizes itself to the same width and height as its parent. It seems to work very well.

Edit: It seems the elements inside a WPF control will happily resize without too much prodding, it's just that they don't detect when the parent host is resized.
Fair enough. Seems like a bit of a chore, though... I really can't imagine something a simple as that was overlooked...
OK - I think I need the award for n00b of the week. If you want something to dock, just remove the width and height definitions from it. Then it will grow to fill whatever element surrounds it. It sounds so simple, I know, but it's just the fact the Windows.Forms ignores the width and height completely when something is docked that threw me. I need to change my mind set really...

Just to note this doesn't work with the top-level control. If you remove the width and height from that then your application becomes 1px x 1px in size... That said, if the top-level control is inside a host that has DockStyle.Fill, then it will obey the rules and fill all the available space.
Glad you found the solution Would never have thought of that, to be honest.
in wpf to dock and anchor
you use Vertical Alignment and Horizontal Alignment along with Margin

I think the idea behind this was to make it familar for non-programers to design user-interfaces (hence xaml) and those members are fairly obvous to understand and also very similar to HTML

*edit* and also the designer in VS2008 is very usefull

[OT] WPF Docking Help
(10 posts, started )
FGED GREDG RDFGDR GSFDG