tags:

views:

46

answers:

2

Hi, I have a grid with 3 rows, in my top row (200px height) i want a text on a blue background. How do i specify that my textblock should fill the space? when i add it it only fits the space the text occupy. Tried with a ViewBox, but that resized the text also, i want that to be a fixed size...

anyone?

A: 

Just remove these four properties from the xaml if they are set when TextBlock is defined, or set them to the default values:

  1. HorizontalAlignment (Defaults to Stretch)
  2. VerticalAlignment (Defaults to Stretch)
  3. Width (Default to Auto)
  4. Height (Default to Auto)

Your TextBlock should now auto stretch and fit the row.

Also make sure that your Grid is also wide enough or is set to fit your Window. Your Grid's width might also be the culprit.

Yogesh
A: 

This code is an example of size autofill for 3 different controls in given grid in XAML. Autofill is default, so you don't need to set anything additional, just make sure margin is not set. I tested this solution in MS Expression Blend and it works OK.

    <Grid Height="400" Width="250" Canvas.Left="100" Canvas.Top="20">
     <Grid.RowDefinitions>
      <RowDefinition Height="200*"/>
      <RowDefinition Height="100*"/>
      <RowDefinition Height="100*"/>
     </Grid.RowDefinitions>
     <Button Content="Button"/>
     <CheckBox Content="CheckBox" Grid.Row="2"/>
     <TextBlock Grid.Row="1" Text="Test Text block" TextWrapping="Wrap"/>
    </Grid>
rochal