天天看點

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中自定義按鈕全局樣式資源并綁定到按鈕

繼續閱讀