2009-06-01 4 views

risposta

6

All'interno l'evento desiderato, è possibile impostare il colore di sfondo come questo ...

// Change the background color of button1 to Blue 
button1.Background = Brushes.Blue; 

È possibile anche impostare questo in un trigger:

<!-- Button will change from Blue to Yellow on MouseOver --> 
<Style TargetType="{x:Type Button}"> 
    <Setter Property="Background" Value="Blue" /> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Background" Value="Yellow" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

Per ancora ulteriori dettagli, controllare il la sezione Property Triggers dell'articolo this.

+2

Un problema con questa soluzione può essere trovato in questa domanda: http://stackoverflow.com/questions/1302756/why-is-the-buttons-background-changing Lo stesso problema è successo a me - sarebbe non sembra impostare lo sfondo. – JJO

+1

Questo codice non funziona: il trigger non viene applicato affatto! – MrAsterisco