【发布时间】:2012-11-21 08:37:50
【问题描述】:
我有一个关于自动样式继承的问题。
基本上,我有一个超类,我想为它定义派生自它的类的文本框和文本块的默认样式。这些样式基于我在 Styles.xaml 中定义的默认样式。
<controls:BaseUserControl.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DisplayLabel}">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Margin" Value="10,0,10,0"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource InputField}">
<Setter Property="Height" Value="30"/>
<Setter Property="Margin" Value="10,0,0,0"></Setter>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
</controls:BaseUserControl.Resources>
这个类叫做DataEntryView。
现在,当我从此类派生时,文本块和文本框只是获得默认的 Windows 外观,而不是我在此处定义的外观。
<views:DataEntryView.Resources>
<!-- Do I need to add anything here? -->
</views:DataEntryView.Resources>
我忘记了什么?
基本上,我不想将每个文本块和文本框的样式显式设置为某个键。
【问题讨论】:
标签: wpf