Live Chat Icon For mobile
Live Chat Icon

WPF FAQ - Expander

Find answers for the most frequently asked questions
Expand All Collapse All

If you require justifying the Expander button to the right, you need to set the FlowDirection property to RightToLeft.

Note: If you set the FlowDirection to RightToLeft, the content of the expander will also be moved to RightToLeft justification. In order to avoid this, you can set the flow direction to expander content. This can be done with the following code snippets,

[XAML]

<Expander FlowDirection="RightToLeft">
            <Expander.Header>
                <TextBlock Text="Expander header content" Background="AliceBlue"
                           Width="{Binding
                           RelativeSource={RelativeSource
                           Mode=FindAncestor,
                           AncestorType={x:Type Expander}},
                           Path=ActualWidth}"/>
            </Expander.Header>
            <Grid FlowDirection="LeftToRight">
                <TextBlock Background="Gray" Text="Expander body content"/>
            </Grid>
</Expander>
Permalink

This example shows how to create an Expander control that contains complex content such as an image and text. The example also encloses the content of the Expander in a ’ScrollViewer’ control.

[XAML]

<Expander Width='200' HorizontalContentAlignment='Stretch'>
   <Expander.Header>
     <BulletDecorator>
       <BulletDecorator.Bullet>
         <Image Width='10' Source='images\icon.jpg'/>
       </BulletDecorator.Bullet>
       <TextBlock Margin='20,0,0,0'>My Expander</TextBlock>
     </BulletDecorator>
   </Expander.Header>
   <Expander.Content>
     <ScrollViewer Height='50'>
       <TextBlock TextWrapping='Wrap'>
         Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
         sed do eiusmod tempor incididunt ut labore et dolore magna 
         aliqua. Ut enim ad minim veniam, quis nostrud exercitation 
         ullamco laboris nisi ut aliquip ex ea commodo consequat. 
         Duis aute irure dolor in reprehenderit in voluptate velit 
         esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 
         occaecat cupidatat non proident, sunt in culpa qui officia 
         deserunt mollit anim id est laborum.
       </TextBlock>
     </ScrollViewer>
   </Expander.Content>
 </Expander>

Permalink

Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.