Search code examples
wpfuser-controlsviewbox

ViewBox default width and height


i've created usercontrol with viewbox as a main container. If i add this usercontrol to a window it will place all area of it. How to set up default width and height for the control?

<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>

Solution

  • There are a number of ways to set the dimensions for a particular control. Hard coding exact Width and Height properties is the least recommended. Instead of that, you could try using the MinHeight, MaxHeight, MinWidth and/or MaxWidth properties that all controls have.

    Another alternative is to set some restrictions using the ColumnDefinitions or WidthDefinitions of a parent Grid if the control resides in one.