2017-06-09 69 views
0

似乎我嘗試使用的menuitem樣式在使用ItemContainerStyle時被完全覆蓋。MenuItem樣式似乎被覆蓋

這裏是當我使用它會發生什麼一個例子:

enter image description here

然而,當我不使用它,這就是我得到:

enter image description here

我更喜歡第二個菜單的外觀,但由於不使用ItemContainerStyle而不支持動態菜單創建。什麼可能會覆蓋風格?我使用Mahapps Dark底色和VS顏色/樣式。

+0

你有沒有試過[支持算法FMP(https://stackoverflow.com/questions/3656814/how-to- ItemContainerStyle'' Style'上的繼承-xaml-style-and-override-property-of-child-element)屬性? –

回答

1

基地你對MetroMenuItem風格的自定義Style

<Style TargetType="MenuItem" BasedOn="{StaticResource MetroMenuItem}"> 
    <Setter Property="Background" Value="Yellow" /> 
</Style> 
+0

感謝您的回答!我將我的項目設置爲在app.xaml中使用MahApps,因此樣式將是全局的。任何線索爲什麼這不會自動基於此? – TheKitchenSink

+0

爲什麼會這樣?這不是隱式風格的工作原理。 – mm8

1

您應該在ItemContainerStyle中使用BaseOn屬性。隨MahApps

<ItemContainerStyle x:Key="MyContainerStyle" BaseOn="{DynamicResource MenuItemStyle}">Style here</ItemContainerStyle>