1
votes

As its container's width shrinks, I'm trying to get Button 1 to wrap its text until it can no longer do so, at which point the horizontal scrollbar kicks in. Right now, the button recognizes that it's got plenty of space due to the scrollviewer and doesn't wrap at all.

<ScrollViewer HorizontalScrollBarVisibility="Auto">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <Button>
      <TextBlock Text="Button 1 - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." 
                 TextWrapping="Wrap" />
    </Button>
    <Button Content="Button 2" Grid.Column="1" />
  </Grid>
</ScrollViewer>

Any ideas?

1
This is what I'd expect from the code. Unless you set a width on the grid or the text block it will be as wide as it needs to be.ChrisF♦
@ChrisF - I agree. This is what I expect from the above code too. I quickly wrote this and then thought, ok, I'm going to add some attached behavior to the the TextBlock.. and then I thought, maybe I should post this on SO to elicit some feedback before I get knee-deep in measuring.Travis Heseman
It's all going to depend on where you want the text to wrap in the first place. After every word? After 10 words?ChrisF♦

1 Answers

0
votes

There you go man:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
     </Grid.ColumnDefinitions>
     <WrapPanel>
         <Button>
             <TextBlock Text="Button 1 - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." 
                        TextWrapping="Wrap" />
         </Button>
     </WrapPanel>
     <Button Content="Button 2" Grid.Column="1" />
</Grid>