简体   繁体   中英

WPF Grid content not showing up inside Expander

My Grid content is invisible when the Grid is put inside an Expander. It is there in the Designer, it lines out the objects as you can see in the image, but it does not show up when the application is launched. What did I do wrong?

Designer screenshot: Screenshot

XAML Code:

<Expander Background="#FFEEEEEE" Opacity="0.95" MouseUp="ResetCursor" x:Name="CatalogusExpander" Header="Catalogus" Width="125" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsExpanded="True" Height="25" ExpandDirection="Up">
    <Grid Height="250" Width="300" HorizontalAlignment="Right" VerticalAlignment="Bottom">
        <TextBlock TextWrapping="Wrap">
            Lorem ipsum dolor sit amet, consectetur
            adipisicing elit, sed do eiusmod tempor incididunt ut
            labore et dolore magna aliqua
        </TextBlock>
    </Grid>
</Expander>

You have set the Height Property of the Expander to 25 and therefore it can not show the Grid because its greater than the given space.

Try this XAML (it takes care of the Header size and expands correctly)

<Expander Background="#FFEEEEEE" Opacity="0.95" MouseUp="ResetCursor" x:Name="CatalogusExpander" Width="125" Header="Catalogus" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsExpanded="True" ExpandDirection="Up" FlowDirection="RightToLeft">
    <Grid Height="250" Width="300" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,-175,0" Background="#FFEEEEEE" FlowDirection="LeftToRight">
        <TextBlock TextWrapping="Wrap">
        Lorem ipsum dolor sit amet, consectetur
        adipisicing elit, sed do eiusmod tempor incididunt ut
        labore et dolore magna aliqua
        </TextBlock>
    </Grid>
</Expander>

You need to put the Grid inside the Expander Content:

<Expander Background="#FFEEEEEE" Opacity="0.95" MouseUp="ResetCursor" x:Name="CatalogusExpander" Header="Catalogus" Width="125" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsExpanded="True" Height="25" ExpandDirection="Up">
    <Expander.Content>
        <Grid Height="250" Width="300" HorizontalAlignment="Right" VerticalAlignment="Bottom">
            <TextBlock TextWrapping="Wrap">
                Lorem ipsum dolor sit amet, consectetur
                adipisicing elit, sed do eiusmod tempor incididunt ut
                labore et dolore magna aliqua
            </TextBlock>
        </Grid>
    </Expander.Content>
</Expander>

您已将扩展器的高度限制为“ 25”,因此即使扩展器的高度也不能超过25。请考虑增加“高度”或删除“高度”属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM