Reputation: 595
I have WPF application and I need to bind two arguments (no matter what they are) to calculate the value (checkbox checked or not). So I have to use IMultiValueConverter
and that's fine.
But is there a way, to give this converter access to DataContext
(ViewModel) of a window I am binding to?
Basically I have some checkboxes in treeview, i need to pass to converter content (text) of theese checkboxes and its parent's header. Then in converter I need to process that text and find out if it's present in some collection I have in my ViewModel (DataContext
). I know that I cannot use ConverterParameter, because it doesn't support binding.
Upvotes: 0
Views: 173
Reputation: 169360
Just add another Binding
to your MultiBinding
that binds to the view model, e.g.:
<MultiBinding Converter="{StaticResource converter}">
<Binding Path="Property1" />
<Binding Path="Property2" />
<Binding Path="DataContext" RelativeSource="{RelativeSource AncestorType=Window}" />
</MultiBinding>
Upvotes: 2