1
我重写代码中某些控件的默认样式。在此之后,我想要禁用所有儿童(深递归)的某些控件的所有自定义样式。例如XAML:如何禁用WPF中的所有自定义样式
<StackPanel>
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="Red"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="Red"/>
</Style>
</StackPanel.Resources>
<Button>red style here is ok</Button>
<TextBlock> also ok</TextBlock>
<StackPanel>
<StackPanel.Resources>
<!-- magic command to disable ALL custom styles, for all controls like
<Style TargetType = "FrameworkElement"/> -->
</StackPanel.Resources>
<Button> no style plz </Button>
<TextBlock> bad style-_- </TextBlock>
</StackPanel>
</StackPanel>
我知道我可以使用样式= null,但对我来说它的坏的解决方案,因为我需要申请这一招对每种类型的控件。我如何解决我的问题?
你想要一个小组的控制风格,没有一个更大的组的风格吧?如果是这种情况,你可以使用命名的资源为你的风格 – Emad
我想风格的大组控件,并没有一大批控件的风格,所以命名风格不是解决方案。 – virty