title: Using a Style Trigger to change another control
body: <p>I have a ListBox and a Button on a Window.  When the ListBox has the focus, the <code>IsEnabled</code> property of the Button should be True.  Here is what I've tried:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type ListBox}"&gt;
      &lt;Setter
          Property="Margin"
          Value="15,0,15,20"&gt;&lt;/Setter&gt;
          &lt;Style.Triggers&gt;
              &lt;Trigger Property="IsFocused" Value="True" /&gt;
              &lt;Setter TargetName="btnActivate" Property="IsEnabled" Value="True" /&gt;
          &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>This seems very straightforward but I get an error message that </p>
  
  <blockquote>
    <p>btnActivate is not recognized.</p>
  </blockquote>
  
  <p>What is the proper way to do this?</p>
  
  <p><strong>EDIT 1</strong>
  I implemented MoonMoo's suggested link as follows:</p>
  
  <pre><code>IsEnabled="{Binding ElementName=lstInactive, Path=SelectedIndex, Converter={StaticResource cvtr}}"&gt;
  </code></pre>
  
  <p>using this converter:</p>
  
  <pre><code>Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
          Dim IsFocused As Integer = CInt(value)
          Return If(IsFocused &gt; -1, True, False)
      End Function
  </code></pre>
  
  <p>This works to turn IsEnabled on when the listbox is focused but does not turn it off when the listbox loses focus.  I think maybe I have to look into a multibinding that also binds to the other control that might get the focus.</p>
  
  <p><strong>EDIT 2</strong>
  I should mention that I tried:</p>
  
  <pre><code>IsEnabled="{Binding ElementName=lstInactive, Path=IsFocused, Converter={StaticResource cvtr}}"&gt;
  </code></pre>
  
  <p>with a converter:</p>
  
  <pre><code>Return CBool(value)
  </code></pre>
  
  <p>but that did not changed the button's IsEnabled property</p>