我正忙于创建一个 WPF(在 C# 中)应用程序,必须使用 Web 浏览器查看报告。应用程序和所有数据都完美显示,除了用于在 Web 浏览器所在页面上导航的菜单项。我读过网络浏览器始终是模态的,因此将始终显示在“前面”。问题是如何让我的菜单项(位于屏幕顶部的菜单中)显示在网络浏览器上?菜单打开,但显然这些项目位于 Web 浏览器后面,用户无法访问。我会更改菜单的流向,但网络浏览器会覆盖页面的整个宽度。
更新:我设法让菜单子项向上显示(在设计视图中看到),试图完全避免 Web 浏览器控制。问题是现在我看不到菜单,我错过了什么?这是将弹出位置设置为“顶部”的代码:
<Page.Resources>
<ControlTemplate x:Key="MenuControlTemplate1" TargetType="{x:Type MenuItem}">
<Popup x:Name="PART_Popup"
AllowsTransparency="true"
Placement="Top"
VerticalOffset="-3"
HorizontalOffset="-2"
IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}"
Focusable="false"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
<Themes:SystemDropShadowChrome Name="Shdw"
Color="Transparent">
<ContentControl Name="SubMenuBorder"
Template="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=SubmenuContent}}"
IsTabStop="false">
<ScrollViewer Name="SubMenuScrollViewer" CanContentScroll="true" MaxHeight="400"
Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}}">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle
Height="{Binding ElementName=SubMenuBorder,Path=ActualHeight}"
Width="{Binding ElementName=SubMenuBorder,Path=ActualWidth}" />
</Canvas>
<ItemsPresenter Name="ItemsPresenter" Margin="2"
KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.DirectionalNavigation="Cycle"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Grid.IsSharedSizeScope="true"/>
</Grid>
</ScrollViewer>
</ContentControl>
</Themes:SystemDropShadowChrome>
</Popup>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation"
Value="true">
<Setter TargetName="PART_Popup"
Property="PopupAnimation"
Value="None"/>
</Trigger>
<Trigger SourceName="PART_Popup"
Property="Popup.HasDropShadow"
Value="true">
<Setter TargetName="Shdw"
Property="Margin"
Value="0,0,5,5"/>
<Setter TargetName="Shdw"
Property="Color"
Value="#71000000"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Page.Resources>