ViewBox 默认宽高

ViewBox default width and height

我创建了以 viewbox 作为主要容器的用户控件。 如果我将此用户控件添加到 window,它将放置它的所有区域。 如何设置控件的默认宽高?

<UserControl>
    ...
    <Viewbox>
        <Grid Height="167" Width="178">
            <ed:RegularPolygon Fill="#FFF4F4F5" InnerRadius="1" PointCount="3" Stroke="Black" RenderTransformOrigin="0.5,0.5" Margin="-39,52,69,52" >
                <ed:RegularPolygon.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="90"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </ed:RegularPolygon.RenderTransform>
            </ed:RegularPolygon>            
        </Grid>
    </Viewbox>
</UserControl>

有多种方法可以设置特定控件的尺寸。硬编码确切的 WidthHeight 属性是最不推荐的。相反,您可以尝试使用所有控件都具有的 MinHeightMaxHeightMinWidth and/or MaxWidth 属性。

另一种方法是使用父级 GridColumnDefinitionsWidthDefinitions 设置一些限制(如果控件位于父级 Grid 中。