XAML Style共同的祖先

时间:2015-03-04 12:35:22

标签: c# xaml windows-runtime windows-store-apps

我将此样式定位为TextBlock

<Style TargetType="TextBlock" x:Key="TahomaBase">
    <Setter Property="FontFamily" Value="Tahoma"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="TextWrapping" Value="NoWrap"/>
</Style>

我是否可以将目标类型更改为textBox和Combobox的共同祖先,以便我将该样式用作两种组件类型的基础?

1 个答案:

答案 0 :(得分:1)

试试这个。

<Style TargetType="TextBlock" x:Key="TahomaBase" BasedOn="{StaticResource YourStyleAncestor}">
        <Setter Property="FontFamily" Value="Tahoma" />
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="TextWrapping" Value="NoWrap"/>
</Style>