1

I want to each row in listbox can display text with word wrap when its width is set to a fix width and the text is longer than the width.

For example, 'This is a long string.' is displayed as one line, but 'This is a long string.This is a long string.This is a long string.' can be displayed as 3 lines as it is one item in list box.

So the height for each row in list box could be different depending on the context.

how to create a simply style for this case?

1
  • Are you looking to do this in XAML or in the code-behind? Commented Jun 21, 2012 at 17:48

1 Answer 1

1

You can do this by modifying the ItemsTemplate

 <ListBox ItemsSource="{Binding YourItems}">
      <ListBox.ItemTemplate>
           <DataTemplate>
                 <TextBlock Text="{Binding TextProperty}" TextWrapping="Wrap"/>
           </DataTemplate>
      </ListBox.ItemTemplate>
 </ListBox>

This assumes your viewmodel has a "YourItems" property that is an IEnumerable and that YourObject has a TextProperty property on it that is a string

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.