I what to draw a circle that uniformly fits into its space, with a constant a stoke thickness. A ViewBox gets me the uniform fit, but not the constant stoke thickness.
<Viewbox Stretch='Uniform' MinHeight='10' MinWidth='10' > <Ellipse Height='10' Width='10' Fill='Red' StrokeThickness='1' Stroke='Yellow'/> </Viewbox>
If you don’t specify a width or height of the ellipse, the default values will be ‘Auto’. Combined with the default HorizontalAlignment/VerticalAligment values of ‘Stretch’, this should cause the ellipse to ‘stretch’ to the width and height of its container (with constant stroke thickness).
The *ContentAlignment properties of the parent container may affect this behavior, but again, the default, unset values should give you the behavior you want.
Edit: revising my suggestion because I did not realized the ellipse must remain a circle (don’t worry, I’ve decided to pick up a copy of ‘Reading for Comprehension’).
I suggest you bind the width and height properties of the ellipse to a MultiBinding of the parent container’s ActualWidth and ActualHeight properties. Then implement a ‘multi-value converter’ that will return the minimum value from the multi-binding.
So the converter might look like this:
And the ellipse properties could be bound like this: