目前我需要在我的應用程序中放置一個「後退」按鈕。這不是要替換硬件後退按鈕,而是要返回到物品的先前狀態,如果用戶不希望繼續他或她對物品的更改。目前,我的MainPage中有以下xaml,它綁定圖像以及將「後退」按鈕放置在視圖上。如何更改按鈕的前景和背景當按下和發佈
MainPage.xaml中
<Grid x:Name="MainPageGrid" Margin="{Binding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width=".2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=".2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image x:Name="currentPhoto" Grid.ColumnSpan="5" Grid.RowSpan="2"
Source="{Binding Source}" Margin="12,0,12,12"
HorizontalAlignment="Center" VerticalAlignment="Center"
toolkit:TiltEffect.IsTiltEnabled="True"/>
<Button x:Name="photoRefreshButton" Grid.Row="0" Grid.Column="5"
BorderBrush="Transparent" Click="photoRefreshButton_Click"
toolkit:TiltEffect.IsTiltEnabled="True">
<Image Source="Assets/Buttons/back.png"/>
</Button>
</Grid>
我希望能夠切換前景色和背景時,按下並釋放按鈕,但我不確定如何改變按鈕模板風格這一點。我想用以下設置:
Not Pressed
Foreground = #FF1BA1E2 (ARGB: 255, 27, 161, 226)
background = transparent
Pressed
Foreground = Current theme foreground brush
background = transparent
編輯
嘗試這對我來說
<Style x:Key="ButtonStyle1" 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 PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="#FF1BA1E2 "/>
</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>
快速的問題,在'Disabled'VisualState上,你的意思是完全刪除第一個'ObjectAnimationUsingKeyFrames>'?此外,如果我要在按鈕周圍放置圓形邊框以模仿默認應用欄按鈕方案,您是否會建議使用後退按鈕創建單個圖像並將其作爲一個圖像進行循環,或者手動在按鈕周圍放置邊框,以及? – Matthew
添加回來,以便在您禁用它時更改您的按鈕。還添加了一個橢圓以顯示圓形「邊框」。 –