locked
I create a TextBolck dynamicly,and add it to a Grid. How to get the max TextBolck's FontSize to meet the Grid's size? RRS feed

  • Question

  • I create a TextBolck dynamicly,and add it to a Grid. How to get the max TextBolck's FontSize to meet the Grid's size?
    Wednesday, March 12, 2014 2:00 PM

Answers

All replies

  • do you mean you want the text in the TextBox to fill the entire grid area? ... or do you just want the TextBox to use the same size font as the parent grid is using?


    -Eric.

    Wednesday, March 12, 2014 9:36 PM
  • yes,I want the text in the TextBox to just fill the entire grid area. THanks
    Thursday, March 13, 2014 4:59 AM
  •    TextBox t = new TextBox();
                t.HorizontalAlignment = HorizontalAlignment.Stretch;
    
                t.VerticalAlignment = VerticalAlignment.Stretch;
                ContentPanel.Children.Add(t);
    This should give you an idea.

    Rahber
    @Rahber

    Thursday, March 13, 2014 5:42 AM
  • I try it,but the fontsize in the grid is small.
    Thursday, March 13, 2014 3:00 PM
  • Put your TextBlock in a Viewbox.

    http://www.geekchamp.com/tips/windows-phone-7-mango-using-viewbox-control

        <Grid Height="200" Width="200">
            <Viewbox>
                <TextBlock Text="hello"/>
            </Viewbox>
        </Grid>

    C# version:
        Grid grid = new Grid() {Height = 200, Width = 200};
        Viewbox vbox = new Viewbox();
        TextBlock tb = new TextBlock() {Text = "hello"};
        vbox.Child = tb;
        grid.Children.Add(vbox);
    

    • Edited by mSpot Inc Thursday, March 13, 2014 4:21 PM
    • Marked as answer by yang2013yang Saturday, March 15, 2014 12:56 PM
    Thursday, March 13, 2014 3:31 PM