title: WPF: Adding a Trigger to a Button
body: <p>I am currently coding a program with a WPF UI and I have a button which is either close or cancel, depending on if there were any changes made on the page.  To achieve this I want to use a trigger (wrapped in a style) on the button so that when the dependency property HasChanges is true the button will change from "Close" to "Cancel".  So far my program displays "Close" as the button's text, but nothing happens when my dependency property HasChanges becomes true. The WPF page is being written in VB.Net and not XAML.</p>
  
  <p>So far I have:</p>
  
  <pre><code>Private Sub SetUpMyButton()
      Me.MyButton.Style = Me.GetMyButtonStyle()
  End Sub
  
  Private Function GetMyButtonStyle() As Style
      Dim hasChangesTrigger as New Trigger
      hasChangesTrigger.Property = CustomControl.HasChangesProperty
      hasChangesTrigger.Value = True
      hasChangesTrigger.Setters.Add(New Setter(Button.ContentProperty, "Cancel"))
  
      Dim hasChangesStyle as New Style
      hasChangesStyle.TargetType = GetType(Button)
      hasChangesStyle.Setters.Add(New Setter(Button.ContentProperty, "Close"))
      hasChangesStyle.Triggers.Add(hasChangesTrigger)
      hasChangesStyle.Seal()
  
      Return hasChangesStyle
  End Function
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>