【问题标题】:Overlaying AvalonDock floating windows; zIndex ignored覆盖 AvalonDock 浮动窗口; zIndex 被忽略
【发布时间】:2018-02-23 00:19:18
【问题描述】:

我正在尝试设置 AvalonDock 浮动窗口的样式,以便我可以在所有窗口上显示覆盖。 我打算将它用于对话服务,然后可以通过用半透明实心画笔覆盖所有浮动窗口来显示“模态”对话框。

我的想法是修改 LayoutAnchorableFloatingWindwoControl 的样式。通用主题的原始样式可以在下面找到 - 包括我注释掉的叠加网格:

<Style x:Key="{x:Type avalonDockControls:LayoutAnchorableFloatingWindowControl}" TargetType="{x:Type avalonDockControls:LayoutAnchorableFloatingWindowControl}">
    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome
                ResizeBorderThickness="10"
                CaptionHeight="16"
                CornerRadius="3,3,3,3"
                GlassFrameThickness="0"
                ShowSystemMenu="True"/>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type avalonDockControls:LayoutAnchorableFloatingWindowControl}">
                <Grid>

                  <!-- My overlay grid:
                    <Grid x:Name="OVERLAY_GRID" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red" Panel.ZIndex="100000"/> 
                  -->

                    <Border  x:Name="WindowBorder" BorderThickness="3" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
                        <Grid Margin="3">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="16"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <Border
                                    Visibility="{Binding Path=Model.IsSinglePane, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}">
                                    <avalonDockControls:DropDownControlArea 
                                        DropDownContextMenu="{Binding Model.Root.Manager.AnchorableContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
                                        DropDownContextMenuDataContext="{Binding Path=SingleContentLayoutItem, RelativeSource={RelativeSource TemplatedParent}}">
                                        <ContentPresenter Content="{Binding Model.SinglePane.SelectedContent, RelativeSource={RelativeSource TemplatedParent}}" 
                                              ContentTemplate="{Binding Model.Root.Manager.AnchorableTitleTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                              ContentTemplateSelector="{Binding Model.Root.Manager.AnchorableTitleTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    </avalonDockControls:DropDownControlArea>
                                </Border>


                                <avalonDockControls:DropDownButton
                                    x:Name="SinglePaneContextMenu" ........../>
                                </avalonDockControls:DropDownButton>

                                <Button ...........>
                                </Button>

                                <Button ........>
                                </Button>

                                <Button .........>
                                </Button>
                            </Grid>
                            <ContentPresenter
                                Content="{TemplateBinding Content}" Grid.Row="1"/>
                        </Grid>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="WindowState" Value="Maximized">
                        <Setter Property="Padding" Value="3" TargetName="WindowBorder"/>
                    </Trigger>
                    <Trigger Property="IsKeyboardFocused" Value="True">
                        <Setter TargetName="WindowBorder"  Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

当我使用带有常规通用主题的原始 MVVMTestApp 时,浮动窗口如下所示:

当我取消注释我的 OVERLAY_GRID 时,您会期望整个窗口被一个巨大的红色块隐藏。但是,有一个问题......

我完全不知道是什么原因造成的。 我已经尝试过显式降低 WindowBorder 和 ContentPresenter 的 Panel.ZIndex 值,但这没有帮助。

我还将 WindowBorder 包装在 AdornerDecorator 元素中,然后尝试在代码中覆盖装饰层,但我遇到了同样的问题; ContentControl 仍然在顶部。我不知道这里发生了什么。

AvalonDock 从 HwndHost 派生类以显示其浮动窗口 - 这会导致 Airpsace 问题导致我的问题吗?再说一次,我实际上认为这只发生在你混合 WinForms 时,而据我所知,所有托管元素都是纯粹的 WPF。

有谁知道是什么原因造成的 - 或者更好的是,如何解决这个问题?

【问题讨论】:

    标签: c# wpf user-interface avalondock


    【解决方案1】:

    仅供参考,如果其他人在未来寻找解决方案,我在这里与开发人员讨论过这个

    http://wpftoolkit.codeplex.com/discussions/651639

    我的解决方案是用另一个控件(例如 ContentPresenter)替换 FloatingWindowContentHost(它使用 HwndHost 来实现 WinForms 兼容性)。相对容易修复,只要您不打算在其中托管任何 WinForms。它确实需要您自己重新编译 AvalonDock,因为这是一个代码更改。

    【讨论】:

    • 链接好像失效了
    猜你喜欢
    • 1970-01-01
    • 2016-05-07
    • 2018-08-04
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 2022-09-23
    • 2011-04-11
    • 1970-01-01
    相关资源
    最近更新 更多