本文介紹了WPF 透明菜單的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我目前有以下菜單:
<Menu Grid.Row="1" Margin="3" Background="Transparent">
<MenuItem Name="mnuFile" Header="File" Background="#28FFAE04" Foreground="#FFFED528">
<MenuItem Name="mnuSettings" Header="Settings" Background="#28FFAE04" Foreground="#FFFED528" />
<MenuItem Name="mnuExit" Header="Exit" Background="#28FFAE04" Foreground="#FFFED528" />
</MenuItem>
<MenuItem Name="mnuView" Header="View" Background="#28FFAE04" Foreground="#FFFED528" />
<MenuItem Name="mnuAbout" Header="About" Background="#28FFAE04" Foreground="#FFFED528" />
</Menu>
我不知道如何使下落的部分變成半透明或完全透明的類似于浮動文本.這樣我就可以看到下面的表格了.
I cannot figure out how to make the part that drops down semi-transparent or completely transparent resembling floating text. So that I can see the form underneath.
任何幫助將不勝感激.謝謝!
Any help would be appreciated. Thanks!
推薦答案
為此,您需要更改 MenuItem 模板.實現您想要的最簡單的模板更改是這樣的:
To do that, you'll need to change your MenuItem template. The simplest template change that achieves what you want is something like this:
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
<Border Name="Border" >
<Grid>
<ContentPresenter
Margin="6,3,6,3"
ContentSource="Header"
RecognizesAccessKey="True" />
<Popup
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsSubmenuOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Fade">
<Border
Name="SubmenuBorder"
SnapsToDevicePixels="True"
Background="Transparent">
<StackPanel
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
</Border>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
<Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="Border" Property="Background" Value="#C0C0C0"/>
<Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/>
<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#888888"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
要進行更多自定義,我建議使用 Blend 來編輯您的樣式/模板或使用 Kaxaml 的簡單樣式作為您樣式的起點.
For more customization, I'd recommend using Blend to edit your styles/templates or using Kaxaml's Simple Styles as a starting point for your styles.
這篇關于WPF 透明菜單的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!