您的位置:首页 > Web前端 > CSS

Visual Studio Ultimate 2012 RC win8 Metro应用的一个小bug-样式继承

2012-06-27 11:49 483 查看
偶然发现Visual Studio Ultimate 2012 RC的一个小bug。

MSDN上的Using based-on styles示例

http://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh465381

<Page.Resources>
<Style x:Key="BasicStyle" TargetType="ContentControl">
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="30" />
</Style>
<Style x:Key="ButtonStyle" TargetType="Button" BasedOn="{StaticResource BasicStyle}">
<Setter Property="BorderBrush" Value="Orange" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Foreground" Value="Orange" />
</Style>
<Style x:Key="CheckBoxStyle" TargetType="CheckBox" BasedOn="{StaticResource BasicStyle}">
<Setter Property="BorderBrush" Value="Green" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Foreground" Value="Green" />
</Style>
</Page.Resources>

<Grid Background="White">
<Button Content="Button" Style="{StaticResource ButtonStyle}"/>
<CheckBox Content="CheckBox"  Style="{StaticResource CheckBoxStyle}"/>
</Grid>


该段代码在 Visual Studio Ultimate 2012 RC 中会报错:Can only base on a Style with target type that is base type of this style's target type.
但实际是可以运行的。

因为Button和CheckBox都继承自ButtonBase,于是我把第二行代码改为<Style x:Key="BasicStyle" TargetType="ButtonBase">,这样就不报错了,同样也能运行。

毕竟是RC版,使用的时候还有一些其它问题,正式版应该会好很多。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: