Button click change Background

Résolu
thefolin Messages postés 56 Date d'inscription mercredi 3 octobre 2012 Statut Membre Dernière intervention 13 mai 2015 - 19 mars 2014 à 16:04
thefolin Messages postés 56 Date d'inscription mercredi 3 octobre 2012 Statut Membre Dernière intervention 13 mai 2015 - 19 mars 2014 à 18:48
Bonjour,
Je développe un application en WP 8.
Je recherche en ce moment comment modifier la couleur du clique d'un bouton en Xaml. Mes recherches porte sur Blend <3 mais rien de concret pour l'instant.

Vos conseil ou votre aide pour le bouton seront le bienvenue.

Crdt

--

1 réponse

thefolin Messages postés 56 Date d'inscription mercredi 3 octobre 2012 Statut Membre Dernière intervention 13 mai 2015
Modifié par thefolin le 19/03/2014 à 18:48
J'ai trouvé je vous donne la solution pour ce qui auront le même problème que moi.

Sélectionner votre bouton et faire un clique droite sur celui-ci.
Sélectionner dans la liste Modifier le modèle puis Modifier une copie puis fenêtre apparaît.
Changer le nom de la ressource ou non :p et faire suivant.

Voici ce que cela vous donne. Tout les propriétés de votre bouton sont mis ici.

  <Style x:Key="RepeatButtonStyle1" TargetType="RepeatButton">
<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 PhoneFontSizeMedium}"/>
<Setter Property="Padding" Value="10,5,10,6"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<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 PhoneButtonBasePressedForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="DarkRed"/>
</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>



Ok c'est un peu le bordelle mais pour régler mon problème on va s'attaquer a une ligne en particulière qui se trouve au début de notre style.
Voici la propriété en question :

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="DarkRed"/>
</ObjectAnimationUsingKeyFrames>

Le Value est notre propriété que l'on va impacter. Ici
Value="Red"
signifie que j'ai mis une couleur rouge.

Bon maintenant il faut appliquer ce style dans notre bouton
Voici la ligne de code :) :
<RepeatButton   ClickMode="Release" Background="#4C8D0000" Foreground="White" Style="{StaticResource RepeatButtonStyle1}">

Cette ligne de code sert a lier mon style a mon bouton :
Style="{StaticResource RepeatButtonStyle1}">


Quand l'utilisateur va sélectionner le bouton le bouton sera rouge

Si il faut changer des choses dit moi ou si ce n'est pas clair
Crdt
0
Rejoignez-nous