Windows phone 7中的图像控件、资源和样式

来源:互联网 发布:沈阳网络营销黑马网络 编辑:程序博客网 时间:2024/06/05 08:23

图像控件:Image,如果在C#代码中动态更改Image的Source,那么会用到BitmapImage类,把BitmapImage赋值给Image.Source。

资源:是Silverlight中任何可重用的值。

    FontFamily="{StaticResource PhoneFontFamilyNormal}"    FontSize="{StaticResource PhoneFontSizeNormal}"    Foreground="{StaticResource PhoneForegroundBrush}"

这种设置属性的样式叫做绑定语法。

但是在项目中又找不到PhoneFontFamilyNormal这样的资源,这是因为在WP7设备本身已经有了嵌入的资源文件。

比如要设置一个button的边框为静态资源,只需要

<Button Content="OK" Margin="40" BorderBrush="{StaticResource PhoneAccentBrush}" />

在VS中自己创建样式,比如要为一个button设置前景色,点击button的property,找到Foreground,先设置好前景色,再如图

如果要自己创建样式,比如自己设置button的style,需要加入一下代码

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="buttonStyle" TargetType="Button">            <Setter Property="BorderBrush" Value="Red" />            <Setter Property="Foreground" Value="Red" />        </Style>
</phone:PhoneApplicationPage.Resources>

在button中需要写入
Style="{StaticResource buttonStyle}"

如果想把Style设置成全局的,那么把
        <Style x:Key="buttonStyle" TargetType="Button">            <Setter Property="BorderBrush" Value="Red" />            <Setter Property="Foreground" Value="Red" />        </Style>

加入到App.xaml的
    <Application.Resources>    </Application.Resources>

标签中

原创粉丝点击