[英]Force ContextMenu to use system resources
我已經在我的app.xaml文件中導入了控件樣式,如下
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
但是對於ContextMenu控件,我想使用wpf內置樣式,該如何覆蓋呢?
將您的ContextMenu
上的Style
設置為null:
<Window x:Class="WpfApplication11.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<Button Content="A metro style button" Height="42" HorizontalAlignment="Left" Margin="12,12,0,0" Name="button1" VerticalAlignment="Top" Width="163">
<Button.ContextMenu>
<ContextMenu Style="{x:Null}">
<MenuItem Header="Item1"/>
<MenuItem Header="Item2"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
</StackPanel>
</Window>
如果要隱式地(而不是顯式地)將所有ContextMenus設置為使用默認的非MahApps樣式,請使用:
<StackPanel.Resources>
<Style BasedOn="{x:Null}" TargetType="{x:Type ContextMenu}"/>
</StackPanel.Resources>
沒有將樣式設置為Null。
將樣式設置為空。
如果您還需要將MenuItem
樣式還原為默認樣式,請使用以下命令:
<StackPanel.Resources>
<Style BasedOn="{x:Null}" TargetType="{x:Type ContextMenu}"/>
<Style BasedOn="{x:Null}" TargetType="{x:Type MenuItem}"/>
</StackPanel.Resources>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.