You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WPF Material Design Drawer打开后处于背景层,如何设置使其覆盖前景按钮?

Fixing the DrawerHost Drawer Being Covered by Test Button

Hey there, this is a classic WPF rendering layer issue—within the same Grid container, elements declared later are rendered on top (higher Z-order) by default. Since your Test Button is likely declared after the DrawerHost in the Grid, it's sitting above the opened drawer content. Here are two straightforward fixes:

Option 1: Reorder Elements in the Grid

Move the DrawerHost to be declared after the Test Button in your Grid. This way, the DrawerHost (and its drawer content) will naturally have a higher rendering priority:

<materialDesign:DialogHost>
    <Grid>
        <!-- Test Button comes first -->
        <Button> Test Button </Button>
        <!-- DrawerHost is declared later, so it renders on top -->
        <materialDesign:DrawerHost Margin="0" Height="350" Width="525" HorizontalAlignment="Left" VerticalAlignment="Center" BorderThickness="2" BorderBrush="{DynamicResource MaterialDesignDivider}">
            <materialDesign:DrawerHost.LeftDrawerContent>
                <StackPanel Margin="16" Height="23" >
                    <TextBlock Margin="4" HorizontalAlignment="Center">LEFT FIELD</TextBlock>
                    <Button Command="{x:Static materialDesign:DrawerHost.CloseDrawerCommand}" CommandParameter="{x:Static Dock.Left}" Margin="4" HorizontalAlignment="Center" Style="{DynamicResource MaterialDesignFlatButton}"> CLOSE THIS </Button>
                    <Button Command="{x:Static materialDesign:DrawerHost.CloseDrawerCommand}" Margin="4" HorizontalAlignment="Center" Style="{DynamicResource MaterialDesignFlatButton}"> CLOSE ALL </Button>
                </StackPanel>
            </materialDesign:DrawerHost.LeftDrawerContent>
            <Grid>
                <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Button Command="{x:Static materialDesign:DrawerHost.OpenDrawerCommand}" CommandParameter="{x:Static Dock.Left}" Grid.Row="1" Grid.Column="0" Margin="4">
                        <materialDesign:PackIcon Kind="ArrowLeft" />
                    </Button>
                </Grid>
            </Grid>
        </materialDesign:DrawerHost>
    </Grid>
</materialDesign:DialogHost>

Option 2: Explicitly Set Panel.ZIndex

If you don't want to reorder your elements, you can assign a higher Panel.ZIndex value to the DrawerHost (default Z-index is 0; higher values mean higher rendering layers):

<materialDesign:DialogHost>
    <Grid>
        <materialDesign:DrawerHost Panel.ZIndex="1" Margin="0" Height="350" Width="525" HorizontalAlignment="Left" VerticalAlignment="Center" BorderThickness="2" BorderBrush="{DynamicResource MaterialDesignDivider}">
            <!-- Your existing DrawerHost content here -->
        </materialDesign:DrawerHost>
        <Button> Test Button </Button>
    </Grid>
</materialDesign:DialogHost>

Quick Explanation

The MaterialDesign DrawerHost's drawer content is designed to render on top of the host itself, but if another element in the same parent Grid has a higher natural or explicit Z-order, it will cover the drawer. Both fixes address this by ensuring the DrawerHost (and its drawer) sits above the Test Button in the rendering stack. The first option is generally preferred since it follows WPF's default layout behavior without extra attributes.

内容的提问来源于stack exchange,提问作者user19143260

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 17:12:38