locked
Problem with text wrapping RRS feed

  • Question

  • I have ListBox
                <ListBox Name="SettingsList"
                         ItemTemplate="{StaticResource SettingsItemTemplate}"
                         ItemContainerStyle="{StaticResource ListBoxItemStyle}"
                         />
    
    and templates for them
            <DataTemplate x:Key="SettingsItemTemplate">
                <StackPanel Orientation="Horizontal"
                            Visibility="{Binding Visibility}"
                            toolkit:TiltEffect.IsTiltEnabled="True"
                            Tap="SettingsItem_Tap"
                            Margin="12,6,6,6"
                            >
                    <Image x:Name="IconImage"
                           Source="{Binding Image}"
                           />
                    <StackPanel Orientation="Vertical"
                            >
                        <TextBlock x:Name="TitleTextBlock"
                                   Text="{Binding Name}"
                                   Style="{StaticResource PhoneTextLargeStyle}"
                                   />
                        <TextBlock x:Name="DescriptionTextBlock"
                               Text="{Binding Description}"
                               Style="{StaticResource PhoneTextSubtleStyle}"
                               TextWrapping="Wrap"
                               />
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
    
        <Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    
    ItemsSource is setting in code-behind
                List list = new List();
                list.Add(new BuyApplicationSettingsItem());
                list.Add(new InterfaceSettingsItem() { BasePage = this });
                list.Add(new ApplicationSettingsItem() { BasePage = this });
                list.Add(new DataManagementSettingsItem() { BasePage = this });
                list.Add(new RateApplicationSettingsItem());
                list.Add(new FeedbackSettingsItem());
                list.Add(new AboutSettingsItem() { BasePage = this });
                //
                SettingsList.ItemsSource = list;
    
    The problem is no text wrapping in Description field, so a part of text can not be readed. What is wrong?
    Sunday, May 13, 2012 9:52 AM

Answers

  • Try setting a Width or MaxWidth on either the TextBlock, Stackpanel or parent Stackpanel in your SettingsItemTemplate. 

    The text can't wrap because the TextBlock is growing to fit the text.
    Monday, May 14, 2012 6:09 PM