样式继承问题混合类型

时间:2014-07-28 16:30:03

标签: wpf xaml windows-runtime winrt-xaml

我尝试分解某些具有共同属性的样式。

所以我使用了样式继承,但似乎没有完全实现。

说我有这两种风格:

<Style TargetType="ProgressBar">
    <Setter Property="Height" Value="50"></Setter>
    <Setter Property="Margin" Value="10"></Setter>
</Style>
<Style TargetType="Rectangle">
    <Setter Property="Height" Value="50"></Setter>
    <Setter Property="Margin" Value="10"></Setter>
</Style>

这是我的第一次尝试:

<Style x:Key="BaseStyle" TargetType="FrameworkElement">
    <Setter Property="Height" Value="50"></Setter>
    <Setter Property="Margin" Value="10"></Setter>
</Style>
<Style BasedOn="{StaticResource BaseStyle}" TargetType="ProgressBar"></Style>
<Style BasedOn="{StaticResource BaseStyle}" TargetType="Rectangle"></Style>

它正在运行,但Visual Studio设计器不满意,并显示此错误:

Can only base on a Style with target type that is base type of this style's target type.

AFAIK,如果我信任MSDN,ProgressBarRectangle应继承FrameworkElement

以下是完整代码:

<StackPanel>
    <StackPanel.Resources>
        <!--<Style TargetType="ProgressBar">
            <Setter Property="Height" Value="50"></Setter>
            <Setter Property="Margin" Value="10"></Setter>
        </Style>
        <Style TargetType="Rectangle">
            <Setter Property="Height" Value="50"></Setter>
            <Setter Property="Margin" Value="10"></Setter>
        </Style>-->
        <Style x:Key="BaseStyle" TargetType="FrameworkElement">
            <Setter Property="Height" Value="50"></Setter>
            <Setter Property="Margin" Value="10"></Setter>
        </Style>
        <Style BasedOn="{StaticResource BaseStyle}" TargetType="ProgressBar"></Style>
        <Style BasedOn="{StaticResource BaseStyle}" TargetType="Rectangle"></Style>
    </StackPanel.Resources>
    <ProgressBar Value="50"></ProgressBar>
    <ProgressBar IsIndeterminate="True"></ProgressBar>
    <Rectangle Width="100" Fill="BlueViolet"></Rectangle>
</StackPanel>

请注意,完全相同的代码在设计器和运行时都适用于WPF。

这是VS错误还是WinRT限制?

我做错了吗?

0 个答案:

没有答案