I've read so many solutions to this problem. Every one of them fails to solve my problem. No matter what container I put the control into or what properties I set on the control/container it will not budge. I have a scroll viewer with a control within. I want it to resize with the window when the user resizes it at runtime. All I need is anchor=top, bottom, left, right
. I don't understand why this is so elusive in WPF and why container objects and all kinds of property assignments need to be involved to accomplish what a single property can in Windows Forms. But every solution to this problem still results in my control staying at exactly its design time size as the window is resized at runtime. What's the simple way to get a grip on dynamic control sizing in WPF?
In WPF, you can create a resizable shape by using the Path control. Simply set up your shape's path data and then set the Stretch property to Fill and your shape will resize itself to fit the space available. It even takes into account the stroke thickness.
User Interface Panels. There are six panel classes available in UI scenarios: Canvas, DockPanel, Grid, StackPanel, VirtualizingStackPanel, and WrapPanel.
This has caused me grief as well and AlexK helped me see the light. The trick is NOT to set the Height and Width.... Set these to AUTO
and use the MARGIN
to set the size. Set the HORIZONTALALIGNMENT
and VERTICALALIGNMENT
to STRETCH
and then the anchor functionality works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With