1

I have a grid (layoutroot) of two columns. I have a list of checkboxes in each of these columns. If a checkbox is checked I need to add some text below it. I was unable to find a way to add a textbox below a checkbox dynamically which would not overlap with the checkbox right below it so I thought of adding the text to be added to the CheckBox text and when this text exceeds the width, it should move to a new line.

Now, this is not the case right now. The checkbox trims any text that is larger than its width. Is there are way to let a checkbox grow in height like a "cangrow" property of reports ? Or is there a workaround that would allow me to add a textbox in between two existing checkboxes and expanding the layout vertically ?

Thanks in advance

user3340627
  • 3,023
  • 6
  • 35
  • 80

2 Answers2

0

TextBlock has similar feature to what you refer as "cangrow" in reports. It is TextWrapping property. Therefore, you can set CheckBox's content to be a TextBlock control to achieve that growing text effect :

<CheckBox>
    <TextBlock TextWrapping="Wrap" Text="Some long text here"/>
</CheckBox>
har07
  • 88,338
  • 12
  • 84
  • 137
  • Thank you for your reply, but this way i have to give the textblock a fixed height that will fit all the contents expected and adjust other controls depending on that height, the thing is, I don't know the height of the contents, I don't want to leave a large empty space between the checkboxes if the contents were just 1 line for example. How can I let the wrapped textblock grow to take the space required and push other controls ? – user3340627 Feb 23 '14 at 11:58
  • `Textwrapping="Wrap"` will automatically wrap text to next line if it exceeds maximum width available. [Illustration](http://stackoverflow.com/a/17981215/2998271). See how button height grow automatically when text needs more than single line. If you put the checkbox within proper container (stackpanel for example) controls below it will be pushed as you expect. No need to set fixed height. – har07 Feb 23 '14 at 12:37
  • 1
    StackPanel worked, I was putting it in a wrong container. Thanks a lot ! – user3340627 Feb 23 '14 at 13:02
0

Add the TextBlock in the designer, then set it's visibility to collapsed. Then when you want to display it, set the visibility to visible.

<StackPanel>
<Checkbox />
<TextBlock x:Name="txtMessage" Visibility="Collapsed" Text="Your text here"/>
</StackPanel>
Greg Gum
  • 33,478
  • 39
  • 162
  • 233
  • Thank you for your reply. This solves the problem for wrapping the text, I have two other problems: 1- How can I make the height for this textblock dynamic ? I mean the contents are not fixed. 2- I also don't want these textblocks to overlap other checkboxes below them when they expand to fit the content but push them downwards. Is this possible to achieve any way ? – user3340627 Feb 23 '14 at 12:03
  • They will expand automatically if they are in a stackpanel with the orientation set to "Vertical" Thus they will grow automatically to fit the contents and not overlap. – Greg Gum Feb 24 '14 at 13:03