WPF网格内容未显示在Expander中

时间:2018-12-21 11:23:59

标签: c# wpf xaml

将Grid放在Expander中时,我的Grid内容不可见。它位于设计器中,它按图像中的顺序排列对象,但在启动应用程序时不会显示。 我做错了什么?

Designer屏幕截图: Screenshot

XAML代码:

<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>

3 个答案:

答案 0 :(得分:2)

您已将Expander的{​​{1}}属性设置为25,因此它不能显示Grid,因为它大于给定的空格。

尝试使用此XAML(它可以保护Header的大小并正确展开)

<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>

答案 1 :(得分:0)

您需要将Grid放在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>

答案 2 :(得分:0)

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