天天看点

WP7中自定义按钮全局样式资源并绑定到按钮

1. 在MainPage.xaml中定义按钮的全局样式:边界颜色为红色,前景色为黄色

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

2. 绑定至按钮

<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="134,137,0,0" Name="button1" VerticalAlignment="Top" Width="160" Style="{StaticResource BtnStyle}" />
           

3. 运行效果

WP7中自定义按钮全局样式资源并绑定到按钮

继续阅读