3
A
回答
5
正如你提到的,只是有Expression Blend中生成繼承樣式的副本給你,然後你可以修改狀態。
現在,您可以通過修改不同的VisualState故事板來更改佈局。如果你對如何做到這一點有更詳細的問題,那就問問題而不是元問題!
<Style x:Key="CustomButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
<Setter Property="Padding" Value="10,3,10,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
更新
準確地說,你需要改變追問的VisualState,就是這一部分:
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
的Storyboard.TargetProperty
設置你想改變屬性,即。 Foreground
,Background
或BorderBrush
DiscreteObjectKeyFrame
設置值(如果不需要動畫,則忽略keytime)。
在這裏,我已經將字體顏色更改爲白色,將背景更改爲橙色,將borderbrush更改爲紫色。
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="Orange"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="White"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Purple"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
相關問題
- 1. Windows Phone 7按鈕
- 2. 按鈕顏色-Windows Phone 7
- 3. Windows phone 7按鈕「邊框」
- 4. Windows Phone 7開發延遲按鈕
- 5. Windows Phone 7後退按鈕問題
- 6. 更改按鈕文本 - Windows Phone 7
- 7. Windows Phone 7上的TextWrapping按鈕
- 8. 在Windows Phone 7中的按鈕命令
- 9. 帶圖像的Windows Phone 7按鈕
- 10. silverlight windows phone 7中的按鈕問題
- 11. Windows Phone 7物理按鈕超載
- 12. Windows Phone 7的搜索按鈕
- 13. Windows Phone 7中的透明按鈕
- 14. longlistselector中的windows phone 7按鈕
- 15. Windows Phone 7中的按鈕陣列
- 16. 在VB.net(Windows Phone 7)中動態更改按鈕的文本
- 17. Windows Phone中動態創建按鈕8.1
- 18. Windows Phone 7.5 - 按下按鈕
- 19. Windows Phone電池狀態
- 20. Windows Phone c#,如何在按下狀態時更改按鈕圖像?
- 21. 如何在按下開始按鈕(Windows Phone)時按下「開始」按鈕(Windows Phone)
- 22. 帶按鈕的Windows Phone TextBox
- 23. Windows Phone 8:後退按鈕
- 24. Windows Phone按鈕樣式
- 25. Windows Phone模板和按鈕
- 26. Windows Phone MVVM動畫按鈕
- 27. Windows phone 8.1按鈕造型
- 28. Windows Phone按鈕對齊
- 29. Windows Phone 8後退按鈕
- 30. Windows phone 7 - 保留應用程序狀態
對不起,我非常普遍的問題,所以要具體我不能找到確切的步驟來改變背景顏色或文本顏色的狀態 – Ameen
請參閱更新的答案。 –
謝謝,這是非常有幫助的! – Ameen