首页 > 解决方案 > UWPCommunityToolkit DropShadowPanel 防止网格拉伸

问题描述

我希望网格在屏幕上伸展,同时应用阴影效果,由于某种原因,当放置在 DropShadowPanel 内时,我无法伸展网格。

这是所需结果的示例,但没有阴影效果:

<Grid Background="LightBlue">
    <Grid Background="WhiteSmoke" HorizontalAlignment="Stretch" Height="200" VerticalAlignment="Top" Margin="40"/>
</Grid>

结果:

在此处输入图像描述

这是我的带有 DropShadowPanel 的 xaml:

<Grid Background="LightBlue">
    <controls:DropShadowPanel HorizontalAlignment="Stretch" Margin="40">
        <Grid Background="WhiteSmoke" HorizontalAlignment="Stretch" Height="200" VerticalAlignment="Top"/>
    </controls:DropShadowPanel>
</Grid>

这完全隐藏了第二个网格。

为什么网格在 DropShadowPanel 中的行为不同?

标签: xamluwpuwp-xamlwindows-community-toolkit

解决方案


这完全隐藏了第二个网格。

问题是你没有设置HorizontalContentAlignment. DropShadowPanel我已经修改了您的代码,如下所示。它有效。

<controls:DropShadowPanel Margin="40"
                          VerticalAlignment="Center"   
                          HorizontalAlignment="Stretch"
                          HorizontalContentAlignment="Stretch"
                          >
    <Grid Background="Red" Height="200" HorizontalAlignment="Stretch"/>
</controls:DropShadowPanel>

推荐阅读