welcome to Qijie's Blog 薛其杰

在Windows 8 App中, App Button 的Style都是存储在资源文件中的, 系统自带的资源文件在Common folder下的StandardStyle.Xaml . 里边定义的Style是以健(Key)的形式表示和定义的。

当我们在程序中动态改变一个App Button的Style是, 可以这么写:

            btPicture.Style = (Style)Application.Current.Resources["PicturesAppBarButtonStyle"];

 

还有, 当你自定义一个Style时,  它所BasedOn的Style一定要写在其定义行之前, 不然你就会运行出错。

应用App Button Style的那些Buttons不能够认为写Content属性, 它的Content是在Style中定义的。

要修改显示的Text, 需要更新Style中的 AutomationProperites.Name 的Value值。

    <Style x:Key="HomeAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
        <Setter Property="AutomationProperties.AutomationId" Value="HomeAppBarButton"/>
        <Setter Property="AutomationProperties.Name" Value="Home"/>
        <Setter Property="Content" Value="&#xE10F;"/>
    </Style>

 

posted on 2012-12-20 17:14  零点零一  阅读(648)  评论(0)    收藏  举报