title: Triggers Based on Properties from DataContext
body: <p>Suppose I want to show/hide elements based on Values of Properties from DataContext, how can I acheive it? </p>
  
  <pre><code>// In MainWindow.xaml.cs: DataContext of MainWindow.xaml
  public int Mode { get; set; } 
  </code></pre>
  
  <p>In XAML, I want to show hide elements based on the <code>Mode</code>. How can I make the below work? Or what is the appropriate way of implementing this?</p>
  
  <pre><code>&lt;StackPanel&gt;
      &lt;StackPanel.Triggers&gt;
          &lt;Trigger Property="Mode" Value="1"&gt;
              &lt;Setter TargetName="txt1" Property="Visibility" Value="Visible" /&gt;
              &lt;Setter TargetName="txt2" Property="Visibility" Value="Collapsed" /&gt;
              &lt;Setter TargetName="txt3" Property="Visibility" Value="Visible" /&gt;
          &lt;/Trigger&gt;
          &lt;Trigger Property="Mode" Value="2"&gt;
              &lt;Setter TargetName="txt1" Property="Visibility" Value="Collapsed" /&gt;
              &lt;Setter TargetName="txt2" Property="Visibility" Value="Visible" /&gt;
              &lt;Setter TargetName="txt3" Property="Visibility" Value="Collapsed" /&gt;
          &lt;/Trigger&gt;
      &lt;/StackPanel.Triggers&gt;
      &lt;TextBlock Text="TextBlock 1" x:Name="txt1" /&gt;
      &lt;TextBlock Text="TextBlock 2" x:Name="txt2" /&gt;
      &lt;TextBlock Text="TextBlock 3" x:Name="txt3" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>Currently, the Error I am getting is "<em>Property 'Mode' was not found in type 'StackPanel'.  D:\tmp\WpfApplication1\TriggersAndProperties\MainWindow.xaml</em>"</p>