WordWrap in PanelBar

3 posts, 1 answers
  1. Kakone
    Kakone avatar
    65 posts
    Member since:
    Jan 2010

    Posted 21 Jun 2010 Link to this post

    Hello,

    I have a panel bar like this :
    <telerikNavigation:RadPanelBar DataContext="{Binding Menu}" ItemsSource="{Binding MenuItems}" SelectedItem="{Binding SelectedMenuItem, Mode=TwoWay}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">                                            
      <telerikNavigation:RadPanelBar.ItemTemplate> 
        <telerik:HierarchicalDataTemplate ItemsSource="{Binding Items}"
          <StackPanel Orientation="Horizontal" > 
            <Image Source="{Binding Image, Converter={StaticResource BitmapImageConverter}}" Margin="5 3 5 3" /> 
            <TextBlock Text="{Binding Text}" VerticalAlignment="Center" TextWrapping="Wrap" /> 
          </StackPanel> 
        </telerik:HierarchicalDataTemplate> 
      </telerikNavigation:RadPanelBar.ItemTemplate> 
    </telerikNavigation:RadPanelBar> 

    All is perfect except the text wrapping. The text is always on one line.

    An idea to accomplish this ?

    Cordially,
    Stephane.
  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 24 Jun 2010 Link to this post

    Hello Kakone,

    The issue is caused by the StackPanel used in the DataTemplate. Since the StackPanel thinks its children have unlimited size no wrap is applied. However, you can replace it with a Grid with defined width for the TextBlock, like so:
    <telerik:HierarchicalDataTemplate ItemsSource="{Binding Items}">
         <Grid >
            <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto"/>
                  <ColumnDefinition Width="200"/>
            </Grid.ColumnDefinitions>
            <Image Source="{Binding Image, Converter={StaticResource BitmapImageConverter}}" Margin="5 3 5 3" />
            <TextBlock Text="{Binding Text}" VerticalAlignment="Center" TextWrapping="Wrap" Grid.Column="1"/>
         </Grid>
    </telerik:HierarchicalDataTemplate>
    Give this approach a try and let me know if it works for you.

    Greetings,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Kakone
    Kakone avatar
    65 posts
    Member since:
    Jan 2010

    Posted 24 Jun 2010 Link to this post

    Hello,

    Indeed, I'm stupid (sorry :-)). With a grid, it works better.
    As I don't want to fix the width, I do this :
    <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
     And it works fine !

    Very thanks,
    Kakone.
Back to Top