开发者

WP7 max circle size for orientation

In my WP7 app, I have a user control, with a grid, and an ellipse in the layout root:

<Grid x:Name="LayoutRoot">
    <Grid x:Name="grdCircle">
        <Ellipse x:Name="elCircle" Stroke="#FFB91515" Margin="5"/>
    </Grid>
</Grid>

I drop this on my main page in the WP7 app, and it looks fine in landscape mode, but when I switch to portrait the width expands and the height contracts, so it is no longer a circle. What I want is for the circle to be the max size it can be regardless of the orientation and still stay a c开发者_如何学Goircle.

I've tried putting SizeChanged event on LayoutRoot, and setting the grdCircle width/height to whatever was smaller - the LayoutRoot actual width or the LayoutRoot actual height, but as soon as I do that, changing the orientation doesn't fire the SizeChanged event of LayoutRoot anymore because LayoutRoot also becomes smaller. How can I ensure that my ellipse is always a circle and grows/shrinks based on the orientation?

Edit: By default, the LayoutRoot grid should have horizontal and vertical alignment set to stretch with margins of 0, so shouldn't the LayoutRoot grid always grow to the size of its container?


Maybe you should take adventage of OrientationChanged event of a Page?

Updated

I think that your control is filling all space that is available. If you change orientation then the amount of space is changing - as a result your control is not a square any more. That fact implicates that the ellipse changes its shape from circle to ellipse, because your ellipse is also trying to fill in all available space. To avoid this you can set Stretch property of an ellipse to Uniform. This should resolve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜