1
<ItemsControl ItemsSource="{Binding NavModel.NavCommands, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Grid.Column="0" Grid.Row="1" 
              ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch">
  <ItemsControl.ItemTemplate>
       <DataTemplate>
           <TextBlock Height="20" Margin="10,10,0,0" TextWrapping="Wrap">
               <Hyperlink Command="{Binding Command}">
                    <Run Text="really really raelly long string"></Run>
               </Hyperlink>
            </TextBlock>
       </DataTemplate>
   </ItemsControl>

The grid has width and height defined by various * values.

             <Grid.ColumnDefinitions>
                <ColumnDefinition Width="12*"/>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="77*"/>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="5*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="92*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="6*"/>
            </Grid.RowDefinitions>

I tried this without the ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch" as well.

How can I achieve my desired effect?

Price Jones
  • 1,948
  • 1
  • 24
  • 40
  • I'm pretty sure that creating custom content inside your will circumvent TextWrapping. Perhaps you can put the inside of your – kenny Jul 10 '14 at 13:52
  • Hmm. Makes sense. I wonder if there is a way to get the text to wrap like I need it to in the hyperlink? – Price Jones Jul 10 '14 at 13:53
  • While not exactly your solution http://stackoverflow.com/questions/140996/how-can-i-set-the-text-of-a-wpf-hyperlink-via-data-binding – kenny Jul 10 '14 at 13:55
  • Haven't ran into this before, try putting your TextBlock in a Grid of its own to act as container. You could test @kenny's comment by simply putting a MaxWidth on it which should definitely invoke the wrapping. Worse comes to worse, you could just bind the width to something to do the same but still let resize ability. – Chris W. Jul 10 '14 at 13:55

2 Answers2

4

I feel kinda stupid. The solution is to get rid of the Height property on the textblock :(

<TextBlock Height="20" Margin="10,10,0,0" TextWrapping="Wrap">

should just be

<TextBlock Margin="10,10,0,0" TextWrapping="Wrap">

and it works.

Price Jones
  • 1,948
  • 1
  • 24
  • 40
  • This will be something you won't encounter again. :) – Loetn Jul 10 '14 at 14:00
  • @Loetn nah the height negating wrap thing is something you'll run into again if you work with xaml a lot, it's pretty common. – Chris W. Jul 10 '14 at 14:01
  • @ChrisW. I never ran into this and I work with XAML every day. Maybe I am just lucky. Ooh well, when I encounter this in the future, I will think of this answer. :) – Loetn Jul 10 '14 at 14:05
  • 1
    This is exactly the kind of thing that bites you once, then when someone else has the problem, you find it instantly and they think you are a genius. Valuable lesson learned! – Kik Jul 10 '14 at 14:18
0
<TextBlock>
    <Hyperlink NavigateUri="http://www.microsoft.com" RequestNavigate="Hyperlink_RequestNavigate">
        <TextBlock TextWrapping="Wrap">
            Navigate To Microsoft Navigate To Microsoft Navigate To MicrosoftNavigate To MicrosoftNavigate To Microsoft
        </TextBlock>
    </Hyperlink>
</TextBlock>
paparazzo
  • 44,497
  • 23
  • 105
  • 176