Lucas Bailey
Lucas Bailey

Reputation: 717

How do you wrap text around an image inside a list box item in WPF?

How do you wrap text around an image inside a list box item in WPF? Basically, I want to make a list item template that has an image on the left, then text wraps around it.

I tried using the flow document control, which made it look like I wanted, however when it is inside the list box, if you click inside the boundary for the flow document, the selected event doesn't fire, which defeats the purpose of putting it in a listbox in the first place. Below is a sample of what I am talking about:

<ListBox ScrollViewer.CanContentScroll="False" Height="297" HorizontalAlignment="Left"
    Margin="159,0,0,0" Name="updateList" VerticalAlignment="Top" Width="260">

    <ListBoxItem  Padding="0" Margin="0" BorderBrush="Black" BorderThickness="0,1,0,0"     
        Width="235" Height="150">

<FlowDocumentScrollViewer Padding="0" Margin="0" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" FontStretch="Normal">
                <FlowDocument TextAlignment="Left">
                    <Paragraph Padding="0" Margin="0">
                        <Floater Width="40" Margin="0,0,10,0" Padding="0" HorizontalAlignment="Left">
                            <BlockUIContainer>
                                <Image Source="/quickviewWPF;component/exclaimationPoint.png"  Width="40" />
                            </BlockUIContainer>
                        </Floater>
                        Item Item Item Item Item Item Item Item Item Item Item Item 
                    </Paragraph>
                </FlowDocument>
            </FlowDocumentScrollViewer>
        </ListBoxItem>

Upvotes: 0

Views: 675

Answers (1)

Erick
Erick

Reputation: 486

this feels kind of hacky but on the FlowDocumentScrollViewer you could just add the property "IsHitTestVisible" and set it to false.

Setting IsHitTestVisible will cause the FlowDocumentScrollViewer and everything inside of it to not be clickable and the hit test that is done on click will go through to the ListBoxItem

<FlowDocumentScrollViewer IsHitTestVisible="False" />

Upvotes: 1

Related Questions