Caliburn.Micro
Caliburn.Micro copied to clipboard
Some bindings not working in TabControl
Hello!
I've noticed an issue when using Caliburn.Micro
to connect Views
and ViewModels
in TabControl
. Some of the ElementName
bindings are not working, and what's interesting is that it happens only if there are more than one tab in TabControl
.
I have this issue in many places in my application, and I am attaching a sample application with one of this issues: https://drive.google.com/open?id=0B4RWnYweQI-GVUk1SUVGTmxkZ0E
In this sample there are two TabControls
: left one is using Caliburn.Micro
and the right one is using standard implicit DataTemplates
. I've simulated tab's loading, so tab's contents are shown after a slight delay.
Steps to reproduce:
- Add one tab with a button
- Click header checkbox and notice that it's working in both
TabControls
. - Add one more tab.
- Click header checkbox and notice that checkbox in left
TabControl
is broken, but is working in the right one. This confirms that it isCaliburn.Micro
's issue.
I think that it has something to do with a fact that the tab's View
is collapsed during initialization.
Please fix this issue: I want to use Caliburn.Micro
's capabilities of wiring Views
and ViewModels
instead of writing implicit DataTemplates
.
It's certainly an interesting bug, I'm still looking at what the ultimate cause is. It's definitely something around the collapsed nature of the view as removing the Task.Delay
or default IsReady to true resolves the issue.
If you enable wpf binding tracing, you will see this error in the debug output window:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Root'. BindingExpression:Path=DataContext.AllSelected; DataItem=null; target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1')
Most likely, because of the collapsed view and WPF visual/logical tree and binding magic.
If you implement the BindingProxy from http://stackoverflow.com/questions/15494226/cannot-find-source-for-binding-with-reference-relativesource-findancestor
and replace ElementName binding with:
IsChecked="{Binding Source={StaticResource proxy}, Path=Data.AllSelected, UpdateSourceTrigger=PropertyChanged}"
it works.
(I just tested it using your example project)
I tried to find the issue within caliburn micro, but I have no clue where to start looking for this.
Anyone else?
I've updated the link to sample because it was deleted from the old link.
I've edited the title because the issue is not in ElementName bindings: I have changed the source of a binding to RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}
and the problem is still there.