Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind before setting content #98

Closed
MrJul opened this issue Oct 9, 2014 · 5 comments
Closed

Bind before setting content #98

MrJul opened this issue Oct 9, 2014 · 5 comments
Milestone

Comments

@MrJul
Copy link

MrJul commented Oct 9, 2014

Hello,

When using cal:View.Model, I think the view should be bound to the VM before the control is assigned the view. Basically, it means swapping the calls to SetContentProperty and ViewModelBinder.Bind in View.cs:292.

Why? I'm currently getting "temporary" binding errors because when the view is initially created, the parent DataContext is used - just before being set correctly at the next line. Additionally, this improves performance since there is no DataContext changes: the various controls don't have to be completely bound twice.

I'm using WPF in .NET 4.5.

Note: I'm currently working around this problem by setting the data context in ViewLocator.LocateForModel, but it feels hacky.

@nigel-sampson
Copy link
Contributor

nigel-sampson commented Oct 9, 2014

It's a possibility, my only concern here is that we're already seeing some weird behavior such as #92 when the visual tree is collapsed, if the view isn't in the true visual tree then I worry it would exacerbate this.

@MrJul
Copy link
Author

MrJul commented Nov 24, 2014

@nigel-sampson #98 is this issue :)

I understand this can have an impact on conventions.
I'm not using them because of issues like the one you mentioned (conventions not being applied on a collapsed element), but that doesn't give me the right to force everyone not to use them. Maybe as an option, disabled by default?

@nigel-sampson
Copy link
Contributor

You're right, I'm an idiot, the issue I was referring to was #92.

I may need to some experiments to check the behaviour of BindingScope between platforms and this seems to be mostly an issue in WPF.

@nigel-sampson
Copy link
Contributor

Have run into a timing issue in #349 where this approach solved the problem. Mostly due to the lack of Loaded event in Xamarin.Forms. I think doing this for perf is a real consideration for 4.0.0.

@nigel-sampson nigel-sampson added this to the v4.0.0 milestone Nov 4, 2016
nigel-sampson pushed a commit that referenced this issue Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants