j'appris sur les événements routés dans WPF et j'essaye l'exemple suivant,LeftMouseButtonDown ne fonctionne pas avec des boutons dans les événements routés
Fichier - Window1.xaml
<ScrollViewer VerticalScrollBarVisibility="Auto">
<UniformGrid MouseDown="UniformGrid_MouseDown">
<Button x:Name="Button1">1</Button>
<Button x:Name="Button2">2</Button>
<Button x:Name="Button3">3</Button>
<Button x:Name="Button4">4</Button>
<Button x:Name="Button5">5</Button>
<Button x:Name="Button6">6</Button>
<Button x:Name="Button7">7</Button>
<Button x:Name="Button8">8</Button>
<Button x:Name="Button9">9</Button>
</UniformGrid>
</ScrollViewer>
Fichier - Window1.xaml .cs
private void UniformGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
Button aTargetButton = e.Source as Button;
if (aTargetButton != null)
{
aTargetButton.Background = Brushes.Azure;
aTargetButton.LayoutTransform = new RotateTransform(45);
if (myPreviouslyClickedButton != null)
{
myPreviouslyClickedButton.Background = Brushes.White;
myPreviouslyClickedButton.LayoutTransform = new RotateTransform(0);
}
myPreviouslyClickedButton = aTargetButton;
}
}
lorsque j'ai couru ces extraits, le bouton correspondant subit une transformation angulaire que quand je fais un clic droit dessus (même si je suis abonné pour MouseDown). Pouvez-vous m'aider avec ça?
Mise à jour:
Cet extrait semble fonctionner si je remplace le bouton avec une ellipse. Pourquoi le bouton ne peut-il pas réagir aux clics gauches lorsqu'une ellipse le peut? Aussi les événements ne sont pas augmentés si je clique sur la même ellipse plus d'une fois