title: WPF ValueConverter Binding - Something's Wrong
body: <p>Imagine you have a list of user selections. Depending on what selections the user has made, other selections may not be available anymore.</p>
  
  <p>I have a ValueConverter that could potentially handle this. If it knows what selections are made, it will return a value indicating if the item being converted is still selectable.</p>
  
  <p>The problem is that the only place to know what the user selections are is in the ViewModel for this screen. No problem, I though. I'll make the converter a property on the ViewModel, and in the constructor for the converter, I'll pass a reference to the ViewModel, so that the converter can check the list of selected items any time it wants.</p>
  
  <p>The problem I'm having now is that it doesn't seem to actually be performing any conversions.</p>
  
  <p>To boil it down:
  The ViewModel has a property called MySelectionConverter of type IValueConverter.
  The ViewModel has a list of selected items.
  In the View (of type MyScreen which inherits from UserControl), there is a listbox with items.</p>
  
  <p>The ItemTemplate looks something like this:</p>
  
  <pre><code>&lt;ListBox.ItemTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;Grid Height="Auto" Width="100" VerticalAlignment="Top"  Visibility="{Binding Path=DataContext.MySelectionConverter, RelativeSource={RelativeSource AncestorType={x:Type MyScreen}}}"&gt;
              &lt;TextBlock Text="The user might want to select me." /&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  &lt;/ListBox.ItemTemplate&gt;
  </code></pre>
  
  <p>I suspect something is wrong with my binding. But maybe you just can't do this at all. Any help is appreciated.</p>
  
  <p><strong>Edit:</strong>
  Based on the information I've gained so far, my binding was incorrect. But it turns out that I can't do what I was trying to do. In essence, I was trying to set the converter via a Binding using:</p>
  
  <pre><code>Visibility="{Binding Converter={Binding Path=DataContext.StyleOptionConverter, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:StyleSelectionScreen}}}}
  </code></pre>
  
  <p>Visual studio tells me:</p>
  
  <blockquote>
    <p>A 'Binding' cannot be set on the
    'Converter' property of type
    'Binding'. A 'Binding' can only be set
    on a DependencyProperty of a
    DependencyObject.</p>
  </blockquote>
  
  <p>So, now I guess the problem becomes: In what way I can get around this? I need to have a converter that knows about the state of the ViewModel for the screen it will be used in.</p>