Scale label to fit grid cell RRS feed

  • Question

  • I have a grid where one cell contains a horizontally & vertically centred Label. How do I set the label so it keeps the same relative size compared to the grid cell? I want the label to grow when the window is made bigger.

    Friday, May 2, 2008 11:14 AM

All replies

  • Howdy,

    You should place the label inside a ViewBox and then add the ViewBox as the child of the Grid. The label will then scale as per the functionality of the ViewBox.

    Learn Expression Blend at learnexpressionstudio.com
    Sunday, May 4, 2008 5:58 PM
  • If you set Margin to the Label, that will also work, provided the Grid Itself is growing. I tried by putting a Grid inside of a DockPanel so that when I maximize the window, the Grid will also increase in size and put a Label inside of it with Margin as 10. The Label grew in size to keep the Margin at 10. following is what I did. I used some random colors as Background to clearly show the size of each control

            <Grid DockPanel.Dock="Bottom" Background="Chartreuse">


                    <ColumnDefinition Width="*" />

                    <ColumnDefinition Width="*" />


                <Label Margin="10" Background="Aqua">Hello World</Label>


    MVP Solutions Architect
    Monday, May 5, 2008 4:38 AM