0

I am working on a project in WPF and I have a very strange case concerning my converters on a certain element.

In the following snippet:

<myCtl:Pager IsTabStop="False" Style="{StaticResource MainPager}"
                DataContext="{Binding CurrentView, Converter={StaticResource SectionToPagerDriver}}"
                Visibility="{Binding CurrentView, Converter={StaticResource SectionToVisibility}}"/>

The converter for 'DataContext' will fire, but the converter for 'Visibility' will not. This seems odd to me considering that they are both bound to 'CurrentView' which indeed changes. I have even tried setting the binding mode explicitly to 'TwoWay' but this does nothing to resolve the issue.

Does anyone have a clue why one binding would fire, and the other would not ?

A.R.
  • 15,405
  • 19
  • 77
  • 123
  • if you comment out the `DataContext` part : `DataContext="{Binding CurrentView, Converter={StaticResource SectionToPagerDriver}}"`, will `SectionToVisibility` fire? – Bolu Jul 02 '13 at 14:13
  • Set this to high http://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources.tracelevel.aspx and test – paparazzo Jul 02 '13 at 14:15
  • @Bolu No. On its own it won't even fire. – A.R. Jul 02 '13 at 14:38

1 Answers1

0

When you set the DataContext on your Control, all other bindings will use the new object as their source.

If you check your output window, you'll see a binding error saying that there is no CurrentView property on whatever object is returned by that property.

Instead, you should just do:

<myCtl:Pager IsTabStop="False" Style="{StaticResource MainPager}"
             DataContext="{Binding CurrentView, Converter={StaticResource SectionToPagerDriver}}"
             Visibility="{Binding Converter={StaticResource SectionToVisibility}}"/>
Abe Heidebrecht
  • 30,090
  • 7
  • 62
  • 66
  • You are half right. By removing 'CurrentView' I get the correct behaviour, but there is no Binding error reported in the original case. (otherwise I would have figured it out) – A.R. Jul 02 '13 at 14:40
  • That is odd. Maybe it is because the `Binding` is valid before the `DataContext` changes. – Abe Heidebrecht Jul 02 '13 at 14:44