Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF CheckBox style with the TextWrapping

I need to apply a TextWrapping in the WPF CheckBox.

Please look at this two samples:

<CheckBox>  
  <TextBlock TextWrapping="Wrap"  
             Text="_This is a long piece of text attached to a checkbox."/>  
</CheckBox>

<CheckBox>  
  <AccessText TextWrapping="Wrap"  
              Text="_This is a long piece of text attached to a checkbox."/>  
</CheckBox>

If I use a TextBlock in the Content of the CheckBox, the check element (vertical alignment is top) and the text displays properly, but not the accelerator.

alt text

If I use an AccessText in the Content of the CheckBox, the check element displays wrong (vertical alignment is center).

How can I change the Style of the elements to display this CheckBox correct?

like image 804
Alexander Zwitbaum Avatar asked Jun 01 '10 13:06

Alexander Zwitbaum


2 Answers

If you combine the two you will probably get the effect you desire.

<CheckBox>
    <TextBlock>
        <AccessText TextWrapping="Wrap"  
                    Text="_This is a long piece of text attached to a checkbox."/>  
    </TextBlock>
</CheckBox>
like image 154
wpfwannabe Avatar answered Oct 26 '22 10:10

wpfwannabe


Use VerticalContentAlignment to align the box to the top. Use Padding to adjust text position.

<CheckBox VerticalContentAlignment="Top" Padding="2,-2,0,0">
    <AccessText Text="_This is a long piece of text attached to a checkbox." TextWrapping="Wrap"/>
</CheckBox>
like image 32
YantingChen Avatar answered Oct 26 '22 11:10

YantingChen