我敢肯定,对于嵌套BasedOn
中的Style
声明,无法使用UserControl
,并且能够引用所做的Style
声明在父母UserControl
中-有人可以确认吗?
我尝试了BasedOn="{StaticResource}"
和BasedOn="{DynamicResource}"
,但都没有用。
(下面的伪代码示例)
<Window>
<UserControl>
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
</Style>
</StackPanel.Resources>
<UserControl2> <!--this will reside in a different .xaml file...-->
<Button Content="Hello World">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="????">
<!--is this possible to inherit the red background?-->
<Setter Property="Padding" Value="10" />
</Style>
</Button.Style>
</Button>
</UserControl2>
</StackPanel>
</UserControl