Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Bindings don't work on elements within a collapsed expander

Open a-jackson opened this issue 8 years ago • 3 comments

I have a user control that contains an expander. This control is inside another control and uses cal:Model.Bind="{Binding}". If the expander starts collapsed then the elements within it are not bound using the convention based binding from the element's name.

I've tried to debug this and when it gets to here the elements are not in the namedElements list.

I stepped into that and as far as I can tell, the elements are not found because they are not in the visual tree until the expander is expander so I'm not sure it could be fixed.

It's worth noting, when using a View Model First approach, this doesn't happen and the elements in the collapsed expander are bound exactly as expected.

It look as though both approaches call into ViewModelBinder.Bind so I'm not sure what the difference is.

Attached is a minimal example

ExpanderBindingIssue.zip

I'd appreciate any suggestions for a workaround.

a-jackson avatar Nov 16 '17 10:11 a-jackson

Sorry this slipped through the cracks.

It's definitely known issue around the lack of visual tree on collapsed expanders.

Can you expand on what you mean by view model first approach working?

nigel-sampson avatar Dec 06 '17 00:12 nigel-sampson

In instances where I have a ViewModel and then use a named ContentControl so CM finds the appropriate View for the given VM this issue is not present. The elements within the collapsed expander bind correctly. Attached is a modified version of that last project to demonstrate this

ExpanderBindingIssue-Working.zip

a-jackson avatar Dec 07 '17 15:12 a-jackson

Thanks for that, a very indication of working vs not-working.

I don't have bandwidth at the moment to look into why this difference exists, but it will be a great help when I do.

nigel-sampson avatar Dec 12 '17 02:12 nigel-sampson