在WPF中是否可以使用嵌套用户控件进行样式继承?

时间:2019-01-31 11:37:08

标签: wpf xaml

我敢肯定,对于嵌套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

0 个答案:

没有答案
相关问题