Search code examples
xamluwpuwp-xamlwindows-community-toolkit

UWPCommunityToolkit DropShadowPanel keeps Grid from stretching


I want a grid to stretch across the screen while also having a shadow effect applied, for some reason I can't the grid to stretch when placed inside of a DropShadowPanel.

Here is an example of the desired result, but without a shadow effect:

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

Result:

enter image description here

Here is my xaml with a DropShadowPanel:

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

And this hides the second grid entirely.

Why does the grid act differently inside a DropShadowPanel?


Solution

  • And this hides the second grid entirely.

    The problem is you have not set HorizontalContentAlignment property of DropShadowPanel. I have modified your code like the following. And it works.

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