![](/img/trans.png)
[英]Change background color when hover menuitem but can't show submenu in wpf
[英]wpf MenuItem dropdown background color
我想更改MenuItems下拉菜單的背景顏色,並且發現可以更改它,如果我更改ControlTemplate“ x:Static MenuItem.TopLevelHeaderTemplateKey”。
我從此處復制了controlTemplate並編輯所有顏色,但是現在它說“ StaticResource MenuScrollViewer”是未知的。 我也從同一站點添加了此資源,但是MenuScrollView缺少許多其他資源。
因此,如何編輯此模板,以便可以更改“ MenuItem.TopLevelHeaderTemplateKey”的所有顏色?
模板在您鏈接的頁面中。 或至少是英文版本。 這是菜單滾動按鈕:
<Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}">
<Setter Property="ClickMode" Value="Hover"/>
<Setter Property="MinWidth" Value="0"/>
<Setter Property="MinHeight" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<DockPanel Background="Transparent" SnapsToDevicePixels="true">
<Rectangle x:Name="R1" DockPanel.Dock="Right" Fill="Transparent" Width="1"/>
<Rectangle x:Name="B1" DockPanel.Dock="Bottom" Fill="Transparent" Height="1"/>
<Rectangle x:Name="L1" DockPanel.Dock="Left" Fill="Transparent" Width="1"/>
<Rectangle x:Name="T1" DockPanel.Dock="Top" Fill="Transparent" Height="1"/>
<ContentPresenter x:Name="ContentContainer" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center"/>
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Fill" TargetName="R1" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>
<Setter Property="Fill" TargetName="B1" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>
<Setter Property="Fill" TargetName="L1" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
<Setter Property="Fill" TargetName="T1" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
<Setter Property="Margin" TargetName="ContentContainer" Value="3,3,1,1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
有關整個提取的模板,請參見:
您可以在C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF\\
中的PresentationFramework.*
程序集中找到默認模板以及所有引用的資源。
下載dotPeek或使用其他一些.NET反編譯器對其進行反編譯,查看Resources
> PresentationFramework.*.g.resources
> themes
下的BAML資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.